JOptionPane灰色输出一键式 [英] JOptionPane Grey Out One Button

查看:67
本文介绍了JOptionPane灰色输出一键式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用JOptionPane为用户提供两个选项.根据先前的操作,尽管可能需要禁用其中一个按钮.

I need to use a JOptionPane to give the user two options. Depending on previous actions though one of the buttons may need to be disabled.

JOptionPane是否可以设置禁用或启用任何一个按钮?

Is it possible with JOptionPane to have the ability to set either of the buttons to be disabled or enabled?

我该怎么做?

推荐答案

使用JButton很容易:

It's easy if you use 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);
    }
}

这篇关于JOptionPane灰色输出一键式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆