java - 我的 JRadioButton 使用 setOpaque(false) 更改外观

标签 java swing transparent look-and-feel jradiobutton

我想删除我的 JRadioButton 的背景,但仍保持相同的外观和感觉。 图片会自己说话:

当我执行这段代码时:

JRadioButton myJRadioButton = new JRadioButton("My JRadioButton");
add(myJRadioButton);

我明白了:

enter image description here

当我用这段代码运行它时:

JRadioButton myJRadioButton = new JRadioButton("My JRadioButton");
myJRadioButton.setForeground(Color.white); //To see it on the black background.
myJRadioButton.setOpaque(false); 
add(myJRadioButton);

我明白了:

enter image description here

我有一个类似“星星”的东西,而不是一个又大又漂亮的圆圈。 而我想要的是保留第一张图片的伟大而美丽的圆圈,但没有根据它的默认背景。

最佳答案

文件说

public void setOpaque(boolean isOpaque)  

If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through. The default value of this property is false for JComponent. However, the default value for this property on most standard JComponent subclasses (such as JButton and JTree) is look-and-feel dependent.

它说明了一切。

关于java - 我的 JRadioButton 使用 setOpaque(false) 更改外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25762775/

相关文章:

java - 我看不到按钮 - (遵循教程)

swing - JDialog - 如何更改图标

uiview - 将 UIView 保存为透明 PNG

java - ICal4j 中的递归规则

java - 忽略争论

java - java中的比较器和可比较的负面场景

java - 通过Android手机使用java通过PC发送短信

java - 根据按下的键更改标签文本

css - 提交按钮透明但不是文字

iphone - 如何为 AVVideoComposition 设置透明背景?