Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 295493

Summary: [SWT/AWT] cannot give focus to embeded JTextField
Product: [Eclipse Project] Platform Reporter: Grant Gayed <grant_gayed>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Silenio Quarti <Silenio_Quarti>
Severity: normal    
Priority: P3 CC: aheckmeier, nrey
Version: 3.6Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard: stalebug

Description Grant Gayed CLA 2009-11-18 12:54:59 EST
- run the snippet below
  -> try to five focus to the JTextField by clicking in it and it won't work
- change useSWT to false and run the snippet again
  -> focus can be given to the JTextField by clicking in it

import java.awt.*;
import javax.swing.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Composite;

public class MainView {
	static boolean useSWT = true;
	public static void main(String[] args) {
		if (useSWT) {
			Display display = new Display();
			Shell shell = new Shell(display);
			shell.setBounds(10, 10, 200, 200);
			shell.setLayout(new FillLayout());
			Composite composite = new Composite(shell, SWT.EMBEDDED);
			Frame f = SWT_AWT.new_Frame(composite);
			populate(f);
			shell.open();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) display.sleep();
			}
			display.dispose();
		} else {
			Frame f = new Frame("awt");
			populate(f);
			f.setSize(500, 100);
			f.setVisible(true);
		}
	}

	static void populate(Frame f) {
		JFrame frame = new JFrame("");
		Container container = frame.getContentPane();
		container.setLayout(new BorderLayout());
		JPanel labelPanel = new JPanel();
		JTextField repeatIndex = new JTextField();
		repeatIndex.setText("              ");
		labelPanel.add(repeatIndex);
		container.add(labelPanel, BorderLayout.NORTH);
		Container frameInfo = frame.getContentPane();
		f.add(frameInfo);
	}
}
Comment 1 aheckmeier CLA 2009-11-26 12:58:42 EST
Maybe a hint?

Is it a Java or SWT problem?
It worked fine with Java 1.5.x but not with Java 1.6.0_15

Anton
Comment 2 Nicolas FR CLA 2010-09-09 09:11:28 EDT
Hi all,

My code works fine in 1.5 and 1.6 just after I add this :

[
container = jFrame.getContentPane();
frame = SWT_AWT.new_Frame(getViewComposite());

...]

    	Panel panelAWT = new Panel();
    	panelAWT.setLayout(new java.awt.GridLayout(1,1)); 
    	panelAWT.add(container);
    	frame.add("Center", (panelAWT));

Good luck
Comment 3 Leo Ufimtsev CLA 2017-08-03 12:27:30 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 4 Eclipse Genie CLA 2019-12-30 13:47:52 EST
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.

--
The automated Eclipse Genie.