값 배열에서 채워지는 Jtable이 있습니다. 내 코드는 다음과 같다 :특정 열 값을 가진 JTable 전체 행의 색을 변경하는 방법
private static final String[] columnNames = {"Line Number", "Error","Fix Proposed","Percentage (%)"};
static DefaultTableModel model = new DefaultTableModel(null,columnNames);
public static void DisplayMyJList(List<CaptureErrors> x,String extension,
ArrayList<Integer> l,ArrayList<Integer> p,
ArrayList<String> e,ArrayList<String> s) throws IOException {//Method to Dynamic get values to be populated in Jtable.
String theExtension = extension;
if(FILE_EXTENSION.equals("java")) {
for(CaptureErrors ex: x) {
Vector row = new Vector();
row.add(ex.getLinenumber());
row.add(ex.getMyfounderror());
row.add(ex.getMycorrection());
row.add(ex.getMyPercentage()+"%");
model.addRow(row);
//model.setRowColour(1, Color.YELLOW);
}
}
table = new JTable(model);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setFillsViewportHeight(true);
table.setShowGrid(true);
table.setShowVerticalLines(true);
table.setGridColor(new Color(0,128,0));
JTableHeader header = table.getTableHeader();
table.setBackground(new Color(255,228,225));
table.setEnabled(true);
header.setFont(new Font("Dialog", Font.CENTER_BASELINE, 12));
header.setBackground(Color.black);
header.setForeground(Color.yellow);
JScrollPane pane4 = new JScrollPane(table);
는 내가하는 JButton를 사용하여 값의 배열 JTable가 채울 수 있습니다. "%"열에이 열의 모든 값을 30보다 높게 설정하면 color.red 행이 강조 표시됩니다.
사용자 싶습니다 TableCellRendererComponent.이 작업을 Jbutton을 클릭하면 수행 할 수 있습니다.
는 실제 JTable는, 다음과 같습니다 : 그럼 취득하는 내용에 따라
는 처음 2 개 행이 빨간색으로 강조되어야한다. 어떤 도움을 주셔서 감사합니다.
테이블은 모든 데이터를 문자열로 취급합니다. 적절한 클래스를 반환하기 위해서'getColumnClass()'메소드를 오버라이드해야한다. 그래서 각 컬럼이 올바르게 포맷 될 수있다. – camickr