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;
}
}
[SSCCE](http://sscce.org/)を投稿してください。 – Moonbeam
なぜDefaultCellEditorを拡張していますか?その必要はありません。 – camickr