M
Markus Puustinen
I have JPopupMenu extending editable JComboBox as a cell editor in
JTable. I can set/get the value fine with actionPerformed when pressin
Enter but I can't get the value when moving focus to another cell with
mouse or tab-key. Focuslisterer doesn't help becouse for some reason
focuslost gets called when I enter the cell not on exit. Can anybody
help me?
Here is the cell editor:
-----------------------------------------------------
public class CellEditorPopup extends AbstractCellEditor implements
TableCellEditor, ActionListener{
private JComboBox comboBox;
public static JTable table;
public static int row;
public static int column;
public static String cellvalue;
public CellEditorPopup() {
comboBox = new PopupEditor(AktiiviNayttoView.popupMenu);
}
public Component getTableCellEditorComponent(JTable table, Object
value, boolean isSelected, int row, int column) {
this.table = table;
this.row = row;
this.column = column;
comboBox.setBorder(BorderFactory.createLineBorder(Color.BLACK,
2));
comboBox.addActionListener(this);
comboBox.setEditable(true);
comboBox.addItem(value.toString());
comboBox.setSelectedItem(value.toString());
comboBox.getEditor().selectAll();
cellvalue = value.toString();
return comboBox;
}
public Object getCellEditorValue() {
return cellvalue;
}
public void actionPerformed(final ActionEvent event) {
Object combo = ((JComboBox) event.getSource()).getSelectedItem();
this.cellvalue = combo.toString();
this.stopCellEditing();
}
}
JTable. I can set/get the value fine with actionPerformed when pressin
Enter but I can't get the value when moving focus to another cell with
mouse or tab-key. Focuslisterer doesn't help becouse for some reason
focuslost gets called when I enter the cell not on exit. Can anybody
help me?
Here is the cell editor:
-----------------------------------------------------
public class CellEditorPopup extends AbstractCellEditor implements
TableCellEditor, ActionListener{
private JComboBox comboBox;
public static JTable table;
public static int row;
public static int column;
public static String cellvalue;
public CellEditorPopup() {
comboBox = new PopupEditor(AktiiviNayttoView.popupMenu);
}
public Component getTableCellEditorComponent(JTable table, Object
value, boolean isSelected, int row, int column) {
this.table = table;
this.row = row;
this.column = column;
comboBox.setBorder(BorderFactory.createLineBorder(Color.BLACK,
2));
comboBox.addActionListener(this);
comboBox.setEditable(true);
comboBox.addItem(value.toString());
comboBox.setSelectedItem(value.toString());
comboBox.getEditor().selectAll();
cellvalue = value.toString();
return comboBox;
}
public Object getCellEditorValue() {
return cellvalue;
}
public void actionPerformed(final ActionEvent event) {
Object combo = ((JComboBox) event.getSource()).getSelectedItem();
this.cellvalue = combo.toString();
this.stopCellEditing();
}
}