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]
# 1
> Also I have a key binding in the panel,The key binding should be on the table.
camickra at 2007-7-13 0:31:26 > top of Java-index,Desktop,Core GUI APIs...
# 2
Which table ? A or B ?
moroshkoa at 2007-7-13 0:31:26 > top of Java-index,Desktop,Core GUI APIs...
# 3
My guess would be the table you are having problems with, namely A.ICE
icewalker2ga at 2007-7-13 0:31:26 > top of Java-index,Desktop,Core GUI APIs...
# 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();

}

});

}

}

moroshkoa at 2007-7-13 0:31:26 > top of Java-index,Desktop,Core GUI APIs...
# 5
> on one of the small tables I want g(...) to be called Maybe I don't understand the question but you need to add the binding to the small tables.You have 3 tables. You only added the binding to the large table.
camickra at 2007-7-13 0:31:26 > top of Java-index,Desktop,Core GUI APIs...
# 6
which table you press g key it suppose have a bind not another one.
suryanto_soa at 2007-7-13 0:31:26 > top of Java-index,Desktop,Core GUI APIs...