我有以下情况:
MessageBox messageBox = new MessageBox(GetShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setText("Question");
messageBox.setMessage("Message");
int answer = messageBox.open();
这会输出一个消息框,其中预先选择了"is"按钮。是否可以将初始选择的"is"更改为“否”,或者只能通过对话框来完成?
最佳答案
不,没有办法做到这一点。这种行为是给定的。不过,您可以通过添加两个按钮并在您想要的按钮上调用 forceFocus
来创建自己的对话框:
Button button1 = new Button(shell, SWT.PUSH);
Button button2 = new Button(shell, SWT.PUSH);
button1.setText("Click me!");
button2.setText("Look at me, I have the focus now.");
//Here you set the focus to the second button
button2.forceFocus();
button1.setBounds(0, 0, 100, 30);
button2.setBounds(200, 0, 200, 30);
shell.pack();
shell.open();
//Prevent from closing
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
关于java - 更改 Java 中 MessageBox 中按钮的预选?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42573675/