[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: WEmbeddedFrame (keyboard events)
|
The problem is that the WEmbeddedFrame is not notified when
it's window, which is a SWT Shell, becomes the active
window. I believe that the AWT mechanism to determine which
lightweight component has focus relies on the fact that the
frame receives that notification.
Here is some code that makes a JTextField receive focus. It
won't work properly if the text field looses focus to another
SWT widget in the same Shell.
Silenio
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.internal.awt.win32.*;
import javax.swing.*;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.WindowEvent;
public class AWTInSWT {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(100, 100, 300, 50);
final java.awt.Panel panel = SWT_AWT.new_Panel(shell);
panel.setLayout(new java.awt.BorderLayout());
final JTextField t = new JTextField();
panel.add(t);
Container temp = panel;
while (temp.getParent() != null) {
temp = temp.getParent();
}
final Frame frame = (Frame)temp;
shell.addListener(SWT.Activate, new Listener() {
public void handleEvent(Event e) {
if (shell.isDisposed()) return;
frame.dispatchEvent(new WindowEvent(frame,
WindowEvent.WINDOW_ACTIVATED));
}
});
shell.addListener(SWT.Deactivate, new Listener() {
public void handleEvent(Event e) {
if (shell.isDisposed()) return;
frame.dispatchEvent(new WindowEvent(frame,
WindowEvent.WINDOW_DEACTIVATED));
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}
Mike Wilson wrote:
> Veronika is away on vacation for the next few weeks. I'll see if I can
> get someone else on the team who was working on this to provide some
> background.
> McQ.
> On Fri, 20 Jul 2001 20:40:55 GMT, Derek Rayside/Toronto/IBM@IBMCA
> <drayside@xxxxxxxxxx> wrote:
> >Hi Veronika,
> >
> >Can you provide any more information as to why the keyboard events do not
work in some cases with Swing embedded in SWT via WEmbeddedFrame? I have been
> >experiencing this problem, and have it on my to do list as something to
look into. Perhaps there are changes I can make to my code so that the
keyboard events work?
> >
> >Thanks,
> >Derek
> >