2011-07-25 3 views
1

各行のセルにコンボボックスが表示されるテーブルを作成しました。私は以下の2つのクラスをそれぞれセルエディターとセルレンダラーとして使用しました。表が表示されているときに、セル内のすべてのコンボボックスがクリックされたときに開かれません。誰も私にヒントを与えることができますか?事前JComboBoxがjTableで開けない

public class CellEditor extends DefaultCellEditor{ 

private static final long serialVersionUID = 1L; 

public CellEditor(String[] items) { 
    super(new JComboBox(items)); 
} 
} 

public class ComboBoxRenderer extends JComboBox implements TableCellRenderer { 
/****/ 
private static final long serialVersionUID = 1L; 

public ComboBoxRenderer(String[] items) { 
    super(items); 
} 

public Component getTableCellRendererComponent(JTable table, Object value, 
     boolean isSelected, boolean hasFocus, int row, int column) { 

    if (isSelected) { 
     this.setForeground(table.getSelectionForeground()); 
     super.setBackground(table.getSelectionBackground()); 
    } else { 
     this.setForeground(table.getForeground()); 
     this.setBackground(table.getBackground()); 
    }   
    this.setSelectedItem(value);// Select the current value  
    return this; 
} 
} 
+0

[SSCCE](http://sscce.org/)を投稿してください。 – Moonbeam

+2

なぜDefaultCellEditorを拡張していますか?その必要はありません。 – camickr

答えて

1

してくださいに感謝がEditors and RenderersUsing a Combo Box as an Editor、このフォーラム(株式会社オートコンプリートJComboBoxのJTableの場合)またはhereまたはhere

上のいくつかの例ですが、基本的にはあなたの質問については、JTableのチュートリアルを読み(設定しているかどうか確認してください)

public boolean isCellEditable(int row, int col) { 
    if (col == someInt) { 
     return true; 
    } else if (col == TableColumnsStartsWithZero) { 
     return true; 
    } else { 
     return false; 
    } 
} 
関連する問題