看板 java 關於我們 聯絡資訊
您可以自己寫一個cellrender,取代原來table的default cell renderer 敝公司的產品中某table有跟您一樣的功能(只是是用ENUM),我是重寫一個CELL RENDERER,CODE給妳參考 ublic class EnumExecutionStatusCellRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof EnumExecutionStatus) { if (status == EnumExecutionStatus.COMPLETED) cell.setForeground(new Color (0, 150, 0)); ...Some more code here if (isSelected) cell.setForeground(Color.WHITE); } return cell; } } ※ 引述《bypang (青菜蘿卜)》之銘言: : 請問如何根据某一Column的boolean值 : 把對應的Row做顏色的改變? : 我嘗試把每一個cell都做一次update,不過出現的結果 : 是每一個cell都一樣顏色??? : // ptm是extends DefaultTableModel : for(int i = 0; i < ptm.getRowCount(); i++) { : boolean isEnabled = Boolean.parseBoolean(ptm.getValueAt(i, : 5).toString()); : for(int j = 0; j < ptm.getColumnCount(); j++) { : DefaultTableCellRenderer renderer = : (DefaultTableCellRenderer)product_tb.getCellRenderer(i, j); : if(isEnableed) { : //System.out.println(i + ", j should be BLUE." ); : //印出來的跟顯示出來的不一樣 : renderer.setBackground(Color.BLUE); : } else { : //System.out.println(i + ", j should be WHITE. " ); : renderer.setBackground(Color.WHITE); : } : } : } : 困擾了很久,希望各位先進不吝賜教,謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 68.49.28.120 ※ 編輯: willieliao 來自: 68.49.28.120 (05/11 13:41)