我想更改面板中显示的表格。但是当我更改TableModel时,标题部分会更改,其他部分不会更改。当我点击它开始显示的单元格时。我该如何解决这个问题?
public void tabloyuDoldur() {
String dizim[][] = new String[planlist.size()][];
for (int i = 0; i < planlist.size(); i++) {
dizim[i] = new String[] { planlist.get(i).getId(), planlist.get(i).getOperation(),
planlist.get(i).getName(), planlist.get(i).getE_rows(), planlist.get(i).getE_bytes(),
planlist.get(i).getCost_cpu(), planlist.get(i).getE_time(), planlist.get(i).getPstart(),
planlist.get(i).getPstop() };
TableModel tabloModeli = new DefaultTableModel(dizim, new String[] { " Id ", "Operation", "Name", "E-Rows",
"E-Bytes", "Cost (%CPU)", "E-Time","E-Temp", "Pstart", "Pstop" });
table.setModel(tabloModeli);
}
table.setDefaultRenderer(Object.class, cell_render_object);
其他表格模型方法
}
public void tabloyuDoldur(int selectedHashValue) {
if (selectedHashValue == 0) {
String dizim[][] = new String[avglist.size()][];
for (int i = 0; i < avglist.size(); i++) {
dizim[i] = new String[] { avglist.get(i).getSql_id(), avglist.get(i).getPlan_hash_value(),
avglist.get(i).getElapAvg(), avglist.get(i).getCpuAvg(), avglist.get(i).getIoAvg(),
avglist.get(i).getClusAvg(), avglist.get(i).getAppAvg(), avglist.get(i).getConcAvg(),
avglist.get(i).getPlsqlAvg() };
TableModel tabloModeli = new DefaultTableModel(dizim, new String[] { "sql_id", "plan hash value",
"ELAP AVG", "CPU AVG", "I/O AVG", "CLUS AVG", "APP AVG", "CONC AVG", "PLSQL AVG" });
table.setModel(tabloModeli);
}
} else {
int i = selectedHashValue - 1;
String dizim[][] = new String[1][];
dizim[0] = new String[] { avglist.get(i).getSql_id(), avglist.get(i).getPlan_hash_value(),
avglist.get(i).getElapAvg(), avglist.get(i).getCpuAvg(), avglist.get(i).getIoAvg(),
avglist.get(i).getClusAvg(), avglist.get(i).getAppAvg(), avglist.get(i).getConcAvg(),
avglist.get(i).getPlsqlAvg() };
TableModel tabloModel = new DefaultTableModel(dizim, new String[] { "sql_id", "plan hash value",
"ELAP AVG", "CPU AVG", "I/O AVG", "CLUS AVG", "APP AVG", "CONC AVG", "PLSQL AVG" });
table.setModel(tabloModel);
}
}
实际上这个问题发生在我用来改变单元格颜色的代码之后。
public class MyTableCellRender extends DefaultTableCellRenderer {
public MyTableCellRender() {
setOpaque(true);
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
String name = (String)value;
String data=name.replaceAll("\\s", "");
if(data.equals("TABLEACCESSFULL"))
setForeground(Color.red);
else if(data.equals("MERGEJOINCARTESIAN"))
setForeground(Color.MAGENTA);
else
setForeground(Color.black);
return super.getTableCellRendererComponent(table,value,
isSelected,hasFocus,row, column);
} }
答案 0 :(得分:0)
String name =(String)value;问题来自这个铸造过程。当你改变它时String name = String.valueOf(value);