我需要使用一个JOptionPane
给用户两个选择。根据之前的操作,可能需要禁用其中一个按钮。
是否可以与JOptionPane
能够将其中一个按钮设置为禁用或启用吗?
我怎样才能做到这一点?
如果您使用 JButtons,这很容易:
public class Test
{
public static void main(String[] args)
{
final JButton option1 = new JButton("option1");
final JButton option2 = new JButton("option2");
option1.setEnabled(false);
// option2.setEnabled(false);
option1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
// code here
}
});
option2.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// code here
}
});
JOptionPane.showOptionDialog(null, "hello", "The Title", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, new JButton[]
{ option1, option2 }, option1);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)