How do I create a JOptionPane.showOptionDialog box in Java (Swing) with custom JButtons?

守給你的承諾、 提交于 2020-01-02 11:03:10

问题


After reading through all the Dialog tutorials for a while, there seems to be no apparent way to do this. The closest thing seems to be JOptionPane.showOptionDialog, but I am limited by the optionType parameter here.

EDIT: I figured out the problem, but have a new one. It seems that the options parameter being specified in showOptionDialog needs to be fairly simple objects (strings or just 'objects', not JButton or the like). I was trying to put an array of custom-factory-created JButtons here, because they have a special rollover icon that I want to be using. What happens, though, is that clicking on any of these buttons does not cause the dialog to close (and thus, execution continues blocking on the dialog). So I have updated my question in the headline.

Put more succinctly -- the question is, how do I override JOptionPane.showOptionDialog(args) to get the button customization I'm looking for? Or do I even need to do that?

Please and thanks! -B.


回答1:


This Java doc should help you create your own dialogs, or customize existing ones: How To Make Dialogs and if thats not what you want then maybe creating a JDialog, adding the necessary components and buttons and making it visible would do the trick :)



来源:https://stackoverflow.com/questions/11145507/how-do-i-create-a-joptionpane-showoptiondialog-box-in-java-swing-with-custom-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!