我正在为我的RCP应用程序中的视图实现CTRL+F
功能。(使用SWT小部件)
为此,每当我按下CTRL + F时,会弹出一个小文本框,用于在视图中键入和搜索。
但是,如果我不输入任何东西或者不关注其他任何东西,它仍会弹出。
我想只显示它5秒钟。 那么,请有人帮忙吗?
提前致谢!
添加代码以获得更多说明: -
final Text findTextBox = new Text(viewer.getTable(), SWT.BORDER);
if ((((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'f'))) {
Rectangle rect = viewer.getTable().getBounds();
findTextBox.setVisible(true);
findTextBox.setFocus();
findtextBox.setLocation(rect.x + rect.width -120, rect.y + rect.height - 25);
findTextBox.setSize(120, 25);
}
答案 0 :(得分:2)
以下是一些仅使用基本Java库和SWT的代码:
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Text text = new Text(shell, SWT.BORDER);
text.setVisible(false);
final Runnable timer = new Runnable()
{
public void run()
{
if (text.isDisposed())
return;
text.setVisible(true);
}
};
display.timerExec(5000, timer);
shell.pack();
shell.setSize(400, 200);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}