如何使用自定义JButton在Java(Swing)中创建JOptionPane.showOptionDialog框? [英] How do I create a JOptionPane.showOptionDialog box in Java (Swing) with custom JButtons?

查看:237
本文介绍了如何使用自定义JButton在Java(Swing)中创建JOptionPane.showOptionDialog框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读完所有对话教程一段时间后,似乎没有明显的方法可以做到这一点。最接近的似乎是 JOptionPane.showOptionDialog ,但我受限于 optionType 参数。

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.

编辑:我发现了问题,但有一个新问题。似乎 showOptionDialog 中指定的选项参数需要是相当简单的对象(字符串或只是'对象',不是 JButton 等。我试图在这里放置一系列自定义工厂创建的JButton,因为它们有一个我想要使用的特殊翻转图标。但是,发生的情况是,单击任何这些按钮不会导致对话框关闭(因此,执行会继续阻止对话框)。所以我在标题中更新了我的问题。

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.

更简洁地说 - 问题是,如何覆盖 JOptionPane.showOptionDialog(args)来获取按钮定制我在找?或者我甚至需要这样做?

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?

请多谢! -B。

推荐答案

这个Java文档应该可以帮助您创建自己的对话框,或者自定义现有对话框:如何制作对话框如果那不是你想要的那么可能会创建一个 JDialog ,添加必要的组件和按钮并使其可见将起到作用:)

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 :)

这篇关于如何使用自定义JButton在Java(Swing)中创建JOptionPane.showOptionDialog框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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