1
我已經創建了一個表格,每行的單元格中顯示了一個組合框。我已經分別使用了以下兩個類作爲單元格編輯器和單元格渲染器。不知何故,當顯示錶格時,單元格中的每個組合框在點擊時都不會打開。任何人都可以給我一個提示嗎?在此先感謝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