Editor problem
Hello friends !
I have the following problem:
I have a panel with 2 JTables:
- Table A which is editable (I wrote my own editor)
- Table B which is not editable
Also I have a key binding in the panel, such that when I press 'g' fuction G(...) called.
Suppose I enter a value in some cell in Table A and then press 'Enter'. At this stage, if I press 'g' I enter the edit mode again, instead of call G(...).
I tried to fix it by calling requestFocus() on Table B inside the stopCellEditing() method of my editor of Table A. But it doesn't work...
Can anyone help me to fix this problem ?
Thanks a lot !!!
[671 byte] By [
moroshkoa] at [2007-11-27 10:00:14]

# 4
OK. I put the binding to the table.
Below is an example of a program.
Again: after I press "1", "Enter","g" on one of the small tables I want g(...) to be called and not enter the edit mode with 'g'.
How should I fix it ?
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.InputMap;
import javax.swing.ActionMap;
import javax.swing.KeyStroke;
import javax.swing.JComponent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
public class TableDemo extends JPanel {
public TableDemo() {
add(new JTable(2, 2));
add(new JTable(3, 3));
JTable table = new JTable(5, 5);
addBindings(table);
add(table);
}
private void addBindings(JTable table) {
InputMap inputMap = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap actionMap = table.getActionMap();
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_G, 0), "G");
actionMap.put("G", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
g();
}
});
}
private void g() {
System.out.println("Hello");
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("TableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TableDemo newContentPane = new TableDemo();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}