blob: 18a2d4fdb4a26fa75188d9290ee4d27da88d3ce0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*******************************************************************************
* Copyright (c) 2018 Red Hat and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.tests.gtk.snippets;
import java.awt.AWTException;
import java.awt.Robot;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
public class Bug516674_control_focus
{
public static void main(String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("TabItem");
Composite composite = new Composite(tabFolder, SWT.NONE);
tabItem.setControl(composite);
composite.setLayout(new GridLayout());
Text text = new Text(composite, SWT.NONE);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
shell.pack();
shell.setSize(500, 500);
shell.open();
tabFolder.setFocus();
Thread thread = new Thread() {
@Override
public void run() {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
text.getShell().forceActive();
text.getShell().forceFocus();
text.forceFocus();
}
});
try {
Thread.sleep(1000);
Robot robot = new Robot();
String string = "this is a test".toUpperCase();
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
robot.keyPress(c);
robot.keyRelease(c);
Thread.sleep(50);
}
} catch (AWTException | InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|