在Java中更改MessageBox中按钮的预选?
我有以下情况:在Java中更改MessageBox中按钮的预选?,java,messagebox,Java,Messagebox,我有以下情况: MessageBox messageBox = new MessageBox(GetShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); messageBox.setText("Question"); messageBox.setMessage("Message"); int answer = messageBox.open(); 这将输出一个消息框,其中预选了“是”按钮。是否可以使用此选项将初始选择
MessageBox messageBox = new MessageBox(GetShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setText("Question");
messageBox.setMessage("Message");
int answer = messageBox.open();
这将输出一个消息框,其中预选了“是”按钮。是否可以使用此选项将初始选择的“是”更改为“否”,或者只能通过对话框执行此操作?否,无法执行此操作。这种行为是给定的。但是,您可以通过添加两个按钮并在要执行以下操作的按钮上调用
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();
不,没有办法。这种行为是给定的。但是,您可以通过添加两个按钮并在要执行以下操作的按钮上调用
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();
MessageBox来自哪个库?抱歉,它来自org.eclipse.swt.widgets.MessageBox;MessageBox来自哪个库?抱歉,它来自org.eclipse.swt.widgets.MessageBox;