Fwd: Focus and key events with SWT_AWT bridge [message #519926] |
Wed, 10 March 2010 09:28  |
Eclipse User |
|
|
|
[Forwarded from RCP platform]
Problem description:
I used Snippet154, because I'm trying to understand
why my Swing component embedded in SWT does not
react on key events. To check what is happenening
here I added
frame.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed : " + e.paramString());
}
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped : " + e.paramString());
}
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased : " + e.paramString());
}
});
immediately before the readAndDispatch loop. Starting the test
program (Windows XP) and pressing any kind of key does not produce
any events (The listener is not called). The problem is: How
do I realize that?
Reason for the question: In my RCP app with a similar SWT_AWT
bridge I cannot call the help for the view presenting this
table. I thought it is related to the focus, but obviously
the table behaves as if it would have focus.
Any ideas are appreciated!
- Daniel
|
|
|
|
|
Re: Fwd: Focus and key events with SWT_AWT bridge [message #520881 is a reply to message #520849] |
Mon, 15 March 2010 12:20  |
Eclipse User |
|
|
|
On 15.03.2010 16:01, Grant Gayed wrote:
> I think the problem is just that AWT events don't bubble, so the Fame is not
> receiving them. I've reduced Snippet154 to an AWT-only snippet below and it
> shows the same behaviour. If the listener is hooked on the JTable instead
> of the Frame then the key events are received, and this is also the case
> when the listener is added to the original Snippet154.
>
> public static void main(String[] args) {
> Frame frame = new Frame();
> Panel panel = new Panel(new BorderLayout()) {
> public void update(java.awt.Graphics g) {
> /* Do not erase the background */
> paint(g);
> }
> };
> frame.add(panel);
> JRootPane root = new JRootPane();
> panel.add(root);
> Container contentPane = root.getContentPane();
> /* Creating components */
> int nrows = 1000, ncolumns = 10;
> Vector rows = new Vector();
> for (int i = 0; i< nrows; i++) {
> Vector row = new Vector();
> for (int j = 0; j< ncolumns; j++) {
> row.addElement("Item " + i + "-" + j);
> }
> rows.addElement(row);
> }
> Vector columns = new Vector();
> for (int i = 0; i< ncolumns; i++) {
> columns.addElement("Column " + i);
> }
> JTable table = new JTable(rows, columns);
> table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
> table.createDefaultColumnsFromModel();
> JScrollPane scrollPane = new JScrollPane(table);
> contentPane.setLayout(new BorderLayout());
> contentPane.add(scrollPane);
>
> frame/*table*/.addKeyListener(new KeyListener() {
> public void keyPressed(KeyEvent e) {
> System.out.println("keyPressed : " + e.paramString());
> }
> public void keyTyped(KeyEvent e) {
> System.out.println("keyTyped : " + e.paramString());
> }
> public void keyReleased(KeyEvent e) {
> System.out.println("keyReleased : " + e.paramString());
> }
> });
>
> frame.setSize(200, 200);
> frame.setVisible(true);
> }
>
> Grant
Thanks Grant, your help is very much appreciated!
All the best,
- Daniel
|
|
|
Powered by
FUDForum. Page generated in 0.04161 seconds