Пожалуйста, пройдите этот учебник для наведения текста на SWT Text
.
Ниже приведена модифицированная версия кода этого урока
package test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class Example {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
GridLayout gridLayout = new GridLayout(2, true);
shell.setLayout(gridLayout);
Label label1 = new Label(shell, SWT.NONE);
label1.setText("First Name");
Text text1 = new Text(shell, SWT.BORDER);
Label label2 = new Label(shell, SWT.NONE);
label2.setText("Last Name");
Text text2 = new Text(shell, SWT.BORDER);
shell.pack();
final HoverShell hShell = new HoverShell(shell);
text1.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
hShell.text.setText("Enter First Name");
hShell.hoverShell.pack();
hShell.hoverShell.open();
}
});
text1.addListener(SWT.MouseExit, new Listener() {
@Override
public void handleEvent(Event event) {
hShell.hoverShell.setVisible(false);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
class HoverShell {
Shell hoverShell;
Text text;
public HoverShell(Shell shell) {
hoverShell = new Shell(shell, SWT.ON_TOP | SWT.TOOL);
hoverShell.setLayout(new FillLayout());
text = new Text(hoverShell, SWT.NONE);
text.setBackground(hoverShell.getBackground());
text.setEditable(false);
}
}
выход