在shell上按键弹出一个窗口继续输入,类似于股票软件选择股票行为

public class Test {

	public static void main(String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
       
        shell.addKeyListener(new KeyListener() {

			@Override
			public void keyPressed(KeyEvent paramKeyEvent) {
				final Shell prompt = new Shell(display, SWT.CLOSE);
		        prompt.setLayout(new FillLayout());
		        final Text t = new Text(prompt, SWT.BORDER | SWT.SINGLE);
		       
		        t.addKeyListener(new KeyListener() {

					@Override
					public void keyPressed(KeyEvent paramKeyEvent) {
						
					}

					@Override
					public void keyReleased(KeyEvent paramKeyEvent) {
						if(t.getText().length() == 0 || paramKeyEvent.keyCode == 13) {
							prompt.close();
						}
					}
		        	
		        });
		        prompt.pack();
		        Point p1 = shell.getSize();
		        Point p2 = prompt.getSize();
		        prompt.setLocation(shell.getBounds().x + p1.x - p2.x - 5, shell.getBounds().y + p1.y - p2.y - 5);
				prompt.open();
				t.append("" + paramKeyEvent.character);
				t.forceFocus();
				
			}

			@Override
			public void keyReleased(KeyEvent paramKeyEvent) {
			}
        	
        });
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
 

你可能感兴趣的:(shell)