所以我想在我的 JTable 中添加一个带有背景颜色的空 JLabel。这是一个饼图,我想添加它以便图例匹配。
代码:
for (String result : queryResult) {
JLabel label = new JLabel("Hallo: "+rowCount);
label.setBackground(colors[rowCount]);
label.setOpaque(true);
String queryResultString = "";
queryResultString = result.toString();
String[] lineArray = queryResultString.split("////");
String[] pieData = new String[3];
pieData[0] = lineArray[0];
pieData[1] = lineArray[rangId - 1];
int value = Integer.parseInt(pieData[1]);
double percentage = value / total * 100;
pieData[2] = "" + percentage + "%";
pieModel.addRow(new Object[] {label, pieData[0], pieData[1], pieData[2]});
rowCount++;
}
pieTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
if(value instanceof JLabel){
//This time return only the JLabel without icon
return (JLabel)value;
}else{
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}
});
我究竟做错了什么?:o
当我查看表格第一列的结果时,它说:
javax.swing.JLabel[,0,0,0...... 看不到其余部分,但它肯定不能正常工作!:(