如何更改JOptionPane内的按钮背景 [英] How to change the button backgrounds inside JOptionPane

查看:409
本文介绍了如何更改JOptionPane内的按钮背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道是否可以更改 JOptionPane 内的按钮的背景颜色。我知道如何使用 UIManager 更改整个 JOptionPane 背景,但知道我想要的是设置个人okButton ,cancelButton等等在 JOptionPane 中分隔各个颜色。如果我可以这样做,我该怎么做?



感谢您的帮助。

解决方案

没有直接的方法可以做到这一点。



但是如果你真的想尝试一下,那么你需要阅读JOptionPane API,它提供代码,显示如何不使用showXXX方法手动创建和显示JOptionPane。



使用这种方法,您现在可以访问actuial JDialog。然后,您可以使用Darryl的 SwingUtils 访问各个按钮,然后设置背景。 p>

代码如下:

  JButton ok = SwingUtils.getDescendantOfType (JButton.class,dialog,Text,Ok); 
ok.setBackground(...);


I was wondering if anybody knew if it was possible to change the background color on the buttons inside a JOptionPane. I know how to change the entire JOptionPane background using a UIManager, but know what I want is to set the individual okButton, cancelButton, and so on within the JOptionPane to separate individual colors. If I can do this, how would I do this?

Thanks for the help.

解决方案

There is no direct way to do this.

But if you really want to give it a try, then you will need to read the JOptionPane API which gives code that shows you how to manually create and display a JOptionPane without using the showXXX methods.

Using this approach you now have access to the actuall JDialog. Then you can use Darryl's SwingUtils to access the individual buttons and then set the background.

The code would be something like:

JButton ok = SwingUtils.getDescendantOfType(JButton.class, dialog, "Text", "Ok");
ok.setBackground(...);

这篇关于如何更改JOptionPane内的按钮背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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