Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Fwd: Focus and key events with SWT_AWT bridge
Fwd: Focus and key events with SWT_AWT bridge [message #519926] Wed, 10 March 2010 14:28 Go to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
[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 #520416 is a reply to message #519926] Fri, 12 March 2010 10:12 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 10.03.2010 15:28, Daniel Krügler wrote:
> [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!

Any ideas so far?

Thanks,

- Daniel
Re: Fwd: Focus and key events with SWT_AWT bridge [message #520849 is a reply to message #520416] Mon, 15 March 2010 15:01 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
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


"Daniel Kr
Re: Fwd: Focus and key events with SWT_AWT bridge [message #520881 is a reply to message #520849] Mon, 15 March 2010 16:20 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
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
Previous Topic:mouseExit triggers on scrollbar??
Next Topic:Displaying animated GIF in table cell, issues with GC
Goto Forum:
  


Current Time: Mon Aug 19 11:49:05 GMT 2019

Powered by FUDForum. Page generated in 0.01795 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top