我在SWT中需要使用showConfirmDialog这个提示框,可是在第一次弹出的时候会隐藏在画面后面,使用ALT+TAB把他切到画面前端后,以后的操作他都会在前端,但是第一次不行,这是为什么?要怎么做才能让他第一次也在前端显示,非常着急。
谁能帮帮忙?
------解决方案--------------------
我这里正常啊
- Java code
public class Test extends Shell { public static void main(String args[]) { try { Display display = Display.getDefault(); Test shell = new Test(display); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } catch (Exception e) { e.printStackTrace(); } } public Test(Display display) { super(display, SWT.SHELL_TRIM); Button button = new Button(this, SWT.NONE); button.addMouseListener(new MouseAdapter() { public void mouseUp(final MouseEvent e) { System.out.println("sss"); JOptionPane.showConfirmDialog(null,"Are you sure you want to clear the log?","Confirm Message", JOptionPane.YES_NO_OPTION); } }); button.setBounds(36, 82, 72, 22); button.setText("New Button"); createContents(); } protected void createContents() { setText("SWT Application"); setLocation(300, 300); setSize(450, 300); } @Override protected void checkSubclass() { }}
------解决方案--------------------
------解决方案--------------------
有问题吗?
- Java code
import javax.swing.JOptionPane;import org.eclipse.swt.*;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.events.MouseListener;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class T { public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); final Button button = new Button(shell, SWT.NONE); button.setText("button"); button.setBounds(20, 15, 155, 25); button.addMouseListener(new MouseListener(){ @Override public void mouseDoubleClick(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseDown(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseUp(MouseEvent arg0) { // TODO Auto-generated method stub JOptionPane.showConfirmDialog(null,"Are you sure you want to clear the log?","Confirm Message", JOptionPane.YES_NO_OPTION); }}); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }}