Summary: | Swing Component loses focus with Display.post(Event) | ||
---|---|---|---|
Product: | [Eclipse Project] Platform | Reporter: | Timo Krieger <t.krieger> |
Component: | SWT | Assignee: | Silenio Quarti <Silenio_Quarti> |
Status: | NEW --- | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | cocoakevin, eclipse.felipe |
Version: | 3.4 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows All | ||
Whiteboard: |
Description
Timo Krieger
2009-01-29 13:10:56 EST
Is the swing compenent embed in SWT ? IMO, this is not a support configuration. Does Swing have support to emulate events? If so you should try using that with Swing application. Here is a test program for this behaviour. On linux it's working, on windows the focus on the Swing JTextField gets lost. public class SwtSwingFocusBug extends Composite { private static int keyChar = 0; public SwtSwingFocusBug(Shell shell, int style) { super(shell, style); FillLayout fl = new FillLayout(); fl.type = SWT.VERTICAL; setLayout(fl); //Create the SWT Text input Composite swtInput = new Composite(this, SWT.NONE); swtInput.setLayout(new FillLayout()); Label swtLabel = new Label(swtInput, SWT.NONE); swtLabel.setText("SWT Input"); Text swtText = new Text(swtInput, SWT.BORDER); //Create the Swing Text input JPanel swingPanel = new JPanel(new GridLayout(1, 2)); swingPanel.add(new JLabel("Swing Input")); swingPanel.add(new JTextField()); Composite swingInput = new Composite(this, SWT.EMBEDDED); Frame frame = SWT_AWT.new_Frame(swingInput); //workaround for java 1.5 bug. Must add heavyweight container to receive mouse events. //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4982522 Panel panel = new Panel(new BorderLayout()); panel.add(swingPanel, BorderLayout.CENTER); frame.add(panel); //Create a Label to create KeyEvents Label key = new Label(this, SWT.BORDER | SWT.CENTER | SWT.NO_FOCUS); key.setText("Press here to post event"); key.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Event evt = new Event(); evt.character = (""+keyChar).charAt(0); evt.type = SWT.KeyDown; getDisplay().post(evt); } public void mouseUp(MouseEvent e) { Event evt = new Event(); evt.character = (""+keyChar).charAt(0); evt.type = SWT.KeyUp; getDisplay().post(evt); keyChar = (keyChar + 1) % 10; } }); } public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); new SwtSwingFocusBug(shell, SWT.NONE); if(!shell.isDisposed()) { shell.pack(); shell.open(); } while(!shell.isDisposed()) { if(!display.readAndDispatch()) { display.sleep(); } } display.dispose(); System.exit(0); } } This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. |