this.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
int par1 = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit", "Exit?", JOptionPane.YES_NO_OPTION);
if(par1==JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
});
这是我的代码。如何设置"否" JOptionPane requestFocus中的按钮?
答案 0 :(得分:2)
使用JOptionPane.showOptionDialog并设置options
和initialValue
参数。
public static int showOptionDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue)
throws HeadlessException
试试这个:
Object[] options = { "YES", "NO" };
int par1 = JOptionPane.showOptionDialog(null, "Are you sure you want to exit", "Exit?",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[1]);
if(par1==0)
{
System.exit(0);
}
答案 1 :(得分:0)
使用此构造函数:
JOptionPane(Object message, int messageType, int optionType,
Icon icon, Object[] options, Object initialValue)
options
表示所有可用按钮,initialValue
是默认选择的按钮。