We Recommend

Java How to Program Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.


Posted By

yoshimov on 08/28/06


Tagged

table java swing grayout


Versions (?)


Grayout a non-editable JTable cell


Published in: Java 


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

  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 

You need to login to post a comment.