I have a cell editor that contains a little button that can be double clicked on to bring up an edit dialog, and then a textfield that can be used to edit the value inline (the popup is required to allow editing of additional values, only the first is shown in the JTable).
When user clicks on field everything is okay, but if they tab into the field they textfield doesn't receive focus and they cannot edit the field unless they click on it with the mouse.
I tried fiddling with the various focus methods of jpanel but it made no difference, anybody know what Im doing wrong ?
package com.jthink.jaikoz.celleditor;
import com.jthink.jaikoz.celldata.Cell;
import com.jthink.jaikoz.guielement.Focus;
import com.jthink.jaikoz.table.CellLocation;
import com.jthink.jaikoz.table.DatasheetToggleButton;
import com.jthink.jaikoz.table.datasheet.Datasheet;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class SimpleMultiRowCellEditor
extends DefaultCellEditor implements ActionListener
{
final JPanel panel;
private final DatasheetToggleButton rowCount;
Cell value;
public SimpleMultiRowCellEditor(final JTextField text)
{
super(text);
this.setClickCountToStart(1);
rowCount = new DatasheetToggleButton();
rowCount.setVisible(true);
rowCount.addActionListener(this);
panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(rowCount);
panel.add(editorComponent);
/*panel.setFocusable(true);
panel.setFocusCycleRoot(true);
ArrayList focusOrder = new ArrayList();
focusOrder.add(editorComponent);
focusOrder.add(rowCount);
focusOrder.add(panel);
panel.setFocusTraversalPolicy(new Focus(focusOrder));
*/
}
public Component getTableCellEditorComponent(
final JTable table, final Object val, final boolean isSelected,
final int row, final int column)
{
value = (Cell) ((Cell) val).clone();
rowCount.setText(String.valueOf(value.getValues().size()));
delegate.setValue(value.getValue());
return panel;
}
public Object getCellEditorValue()
{
final String s = (String) delegate.getCellEditorValue();
value.setValue(s);
return value;
}
public void actionPerformed(final ActionEvent e)
{
this.stopCellEditing();
final CellLocation cl = Datasheet.getActiveEditSheet()
.getTable().getSelectedCellLocations().get(0);
UpdateMultiRowCellDialog.getInstanceOf().display(value,cl);
}
}
Tried adding focuslistener to panel, didnt seem to make any difference
class PanelFocusListener implements FocusListener
{
public void focusGained(FocusEvent e)
{
System.out.println("Gained Focus");
editorComponent.requestFocusInWindow();
}
public void focusLost(FocusEvent e)
{
System.out.println("Lost Focus");
}
}
So after tabbing into field, I type a key and it sorts of look likes focus is gained but you cannot enter anything into the field whereas if I type RETURN then I can start editing the field, what does pressing RETURN do that allows it to work ?