繁体   English   中英

JOptionPane与自定义数组JButtons

[英]JOptionPane with custom array JButtons

我有这个代码,但它不适用于按钮数组

        JButton[] option = new JButton[2];
        option[0].setText("sad");
        option[0].setEnabled(true);
        option[1].setText("sasdd");
        option[1].setEnabled(true);
        Object[] options = {option[0], option[1]};
        int i = JOptionPane.showOptionDialog(null, "SADASD", "dfgdfgg", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

如果我使单个按钮工作完美,但我需要在阵列上控制其中一些。

在设置值之前,您必须创建如下的JButton对象:

option[0] = new JButton();
option[1] = new JButton();

在创建数组后立即写下这一行。

String[] options = {"Java", "C", "C++", "C#"};
String msg = "What is your favourite language";
String title = "Language Poll";
int result = JOptionPane.showOptionDialog(parentComponent, msg, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if(result == options[0] {
    //do some thing
} else {
.......
}

....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM