我需要使用 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);
}
}
关于java - JOptionPane 灰色一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14576196/