JTable problem: set/get cell value on focuslost

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();
}
}
 
K

Kleopatra

Markus said:
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?

[..]


public void actionPerformed(final ActionEvent event) {
Object combo = ((JComboBox) event.getSource()).getSelectedItem();
this.cellvalue = combo.toString();
this.stopCellEditing();
}
}

you have to do the setting of the cellvalue in stopCellEditing because
that's the method called by table (or any other client) when terminating
an edit.


public void actionPerformed(..) {
stopCellEditing();
}

public boolean stopCellEditing() {
cellValue =...
return super.stopCellEditing();
}

Greetings
Jeanette

PS: a more focused group for swing related questions is
comp.lang.java.gui
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top