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

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

问题描述

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

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

myJButton.setBackground(Color.RED);

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

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.

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

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

推荐答案

您是否尝试过设置 JButton.setOpaque(true)?

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天全站免登陆