I want to add Jtable to JComboBox Editor, so when i select the ComboBox the JTable show up.
I can't use table.removeActionListener() and table.addActionListener(). we new functions
table.addAncestorListener( addAncestorListener listener) and
table.removeAncestorListener(addAncestorListener listener)
her is my code so far,
public class CustomComboEditor implements ComboBoxEditor {
private JTable table ;
public CustomComboEditor() {
table = new JTable();
}
@Override
public void addActionListener(ActionListener l) {
// there is no addActionListener(l) for table
}
@Override
public Component getEditorComponent() {
return table ;
}
@Override
public Object getItem() {
return table.getValueAt(table.getSelectedRow(), table.getSelectedColumn());
}
@Override
public void removeActionListener(ActionListener l) {
// there is no removeActionListener(l);for table
}
@Override
public void selectAll() {
table.selectAll();
}
@Override
public void setItem(Object anObject) {
return ;
}
}
her is an image illustrates what i want exactly
While it may be technically possible to use a
JTable
as aComboBoxEditor
, the result may be unwieldy. Instead, add the desired instances of yourTableModel
to the combo'sComboBoxModel
and usesetModel()
to display the selected model in an adjacentJTable
. Summarized below, a complete example is shown here.