Grayout a non-editable JTable cell


/ Published in: Java
Save to your folder(s)

Rendererを作るかJTable#prepareRendererをオーバーライドする。オーバーライドのほうが汎用的に使えて楽。


Copy this code and paste it in your HTML
  1. JTable table = new JTable() {
  2. // 選択不可項目をグレーアウト
  3. public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
  4. Component c = super.prepareRenderer(renderer, row, column);
  5. if (column == 0 && !isCellEditable(row, column)) {
  6. c.setBackground(Color.GRAY);
  7. }
  8. return c;
  9. }
  10. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.