use*_*457 5 java swing joptionpane
我需要使用 aJOptionPane为用户提供两个选项。根据之前的操作,可能需要禁用其中一个按钮。
是否可以将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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1410 次 |
| 最近记录: |