JComboBox ruleComboBox = new JComboBox(); String [] comboArr = {"Include", "Hide Until"}; ItemListener ruleItemListener = null; class CustomComboBoxEditor extends DefaultCellEditor { private DefaultComboBoxModel model; public CustomComboBoxEditor() { super(ruleComboBox); this.model = (DefaultComboBoxModel)((JComboBox)getComponent()).getModel(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (model.getSize() > 0) return super.getTableCellEditorComponent(table, value, isSelected, row, column); for (int i = 0; i < comboArr.length; i++) { model.addElement(comboArr[i]); } return super.getTableCellEditorComponent(table, value, isSelected, row, column); } } ruleItemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int state = e.getStateChange(); debug("state:" + (ItemEvent.DESELECTED == state ? "DESELECTED" : "SELECTED") + " item=" + e.getItem()); }; }; ruleComboBox.addItemListener(ruleItemListener); TableColumn displayRulesCol = tblDashboard.getColumnModel().getColumn(RULE_COLUMN); displayRulesCol.setCellEditor(new CustomComboBoxEditor());
Wednesday, September 14, 2016
Combo box with JTable
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment