如何在Mac OS上设置JButton的背景颜色 [英] How to Set the Background Color of a JButton on the Mac OS

查看:297
本文介绍了如何在Mac OS上设置JButton的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常使用Java Swing,您可以设置按钮的背景颜色:

  myJButton.setBackground(Color.RED) ; 

会导致按钮变红。但在Mac OS上,这种方法似乎被忽略了。该按钮只保留默认颜色。



如何在Mac OS上设置JButton的颜色?

  JButton button =新的JButton(测试); 
button.setBackground(Color.RED);
button.setOpaque(true);


Normally with Java Swing you can set the background color of a button with:

myJButton.setBackground(Color.RED);

which would cause the button to be red. But on the Mac OS, this method seems to be ignored. The button just stays the default color.

How can the color of a JButton be set on the Mac OS?

解决方案

Have you tried setting JButton.setOpaque(true)?

JButton button = new JButton("test");
button.setBackground(Color.RED);
button.setOpaque(true);

这篇关于如何在Mac OS上设置JButton的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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