【问题标题】:Java Swing dialog buttons and iconsJava Swing 对话框按钮和图标
【发布时间】:2013-03-09 15:20:00
【问题描述】:

我目前正在学习 Java,并且正在上一堂教授对话框的课程。 目前我知道如何更改图标选项,但添加一些按钮怎么样?

JOptionPane.showMessageDialog(null, "Text to display", "Title", JOptionPane.WARNING_MESSAGE); 

^ 显示应有的警告错误和确定按钮,但我还想有一个取消按钮

很遗憾

JOptionPane.showMessageDialog(null, "Text to display", "Title", JOptionPane.WARNING_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 

返回错误。基本上,因为我是初学者,所以我不知道在哪里放置 ok_cancel_option 部分。谢谢 ! :D

【问题讨论】:

    标签: java swing button dialog icons


    【解决方案1】:
    JOptionPane.showConfirmDialog(parent, 
                                  "message", 
                                  "title", 
                                  JOptionPane.YES_NO_OPTION);
    

    showMessageDialog() 用于提醒,如果你想要一个确认对话框,你必须使用showConfirmDialog(),如上所示

    PS:忘了说showConfirmDialog()返回结果

    int result = JOptionPane.showConfirmDialog(parent, 
                                               "message", 
                                               "title", 
                                                JOptionPane.YES_NO_OPTION);
    
    if (result == JOptionPane.YES_OPTION){
         //stuff to do if yes
    }
    if (result == JOptionPane.NO_OPTION){
         //stuff to do if no
    }
    

    【讨论】:

    • Multumesc mult pentru raspuns!
    • Cu placere, vezi completarea cum sa primesti raspunsul
    猜你喜欢
    • 2011-02-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    相关资源
    最近更新 更多