2个回答
展开全部
参考这几行代码。Swing里改table显示还是有点小麻烦的
Object[][] data = {{"1", "#0000ff"}, {"2", "#00ff00"}, {"3", "#ff0000"}};
String[] head = {"No.", "Color"};
JTable table = new JTable(data, head);
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Color color = Color.decode((String)table.getValueAt(row, 1));
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
comp.setBackground(color);
return comp;
}
});
Object[][] data = {{"1", "#0000ff"}, {"2", "#00ff00"}, {"3", "#ff0000"}};
String[] head = {"No.", "Color"};
JTable table = new JTable(data, head);
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Color color = Color.decode((String)table.getValueAt(row, 1));
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
comp.setBackground(color);
return comp;
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询