Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Focus Out Problem

How do I receive the Focus out event for all the widgets in
an application for SWT GTK?
It is possible in SWT Win32. Thanks in advance.

public class FocusTest {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	Label label = new Label (shell, SWT.NONE);
	label.setText ("Enter your name:");
	Text text = new Text (shell, SWT.BORDER);
	text.setLayoutData (new RowData (100, SWT.DEFAULT));
	Button ok = new Button (shell, SWT.PUSH);
	ok.setText ("OK");
	ok.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			System.out.println("OK");
		}
	});
	Button cancel = new Button (shell, SWT.PUSH);
	cancel.setText ("Cancel");
	cancel.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			System.out.println("Cancel");
		}
	});
	display.addFilter(SWT.FocusIn, new Listener() {
		@Override
		public void handleEvent(Event event) {
			System.out.println("Focus In");
		}
		
	});
	display.addListener(SWT.FocusOut, new Listener() {
		@Override
		public void handleEvent(Event event) {
			System.out.println("Focus Out"); //Never printed
		}
	});
	shell.setDefaultButton (cancel);
	shell.setLayout (new RowLayout ());
	shell.pack ();
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}



Back to the top