简体   繁体   English

如何防止按钮环绕在Java中显示?

[英]How do I prevent button surround from displaying in Java?

Sorry for the odd choice of words for the title, however, "border" seems to be the inappropriate term. 抱歉,标题的单词选择奇怪,但是“ border”似乎是不合适的术语。 While it is true that the visible line surrounding an icon in a JToggleButton can be made invisible by using setBorderPainted(false), the same is not true for JCheckBox and JRadioButton. 虽然确实可以通过使用setBorderPainted(false)使JToggleButton中的图标周围的可见线不可见,但对于JCheckBox和JRadioButton却并非如此。

I can not use the JToggleButton and therefore need to use either the JCheckBox or JRadioButton (or some derivative of JToggleButton I am not aware of), but need the square or circle, respectively, to be non-visible when there is no icon on the button. 我无法使用JToggleButton,因此需要使用JCheckBox或JRadioButton(或我不知道的JToggleButton的某些派生产品),但是当图标上没有图标时,需要分别使正方形或圆形不可见。按钮。 Also, using setVisible(false) eliminates the button from the layout, however, I need the space to be reserved and not have the component layout change (using GroupLayout). 另外,使用setVisible(false)可以从布局中删除按钮,但是,我需要保留空间,并且不更改组件布局(使用GroupLayout)。

Any suggestions? 有什么建议么? Am I going to have to create a custom renderer? 我是否必须创建一个自定义渲染器? I will be looking at that in the mean time. 同时,我将对此进行研究。

The route into this would be through customising the look at feel by changing some of the UI properties in the UImanager (the sort of thing that allows you to make simple tweaks with fonts and colours and presumably the images used for the checkboxes or radiobuttons) -- but it's many years since I last did that sort of thing and can't remember the details. 解决方法是通过更改UImanager中的某些UI属性来自定义外观(这种东西使您可以对字体和颜色以及可能用于复选框或单选按钮的图像进行简单的调整)- -但是自从我上次做这种事情已经很多年了,不记得细节了。

A little Googling turned up this project to inspect current property values, so might at least help with indicating the right part of the APIs to be looking at. 稍加谷歌搜索这个项目来检查当前的属性值,因此至少可以帮助指示要查看的API的正确部分。

You have to choices here: 您必须在这里选择:

1) Customize Look and Feel as described in previous entry. 1)按照上一个条目中的描述自定义外观。

2) Create your own custom controls by inheriting from existing ones and overriding component painting. 2)通过继承现有控件并覆盖组件绘制来创建自己的自定义控件。

I found a cheap and easy (read hack) for this. 我为此找到了便宜又容易的方法(阅读技巧)。 I created an empty transparent icon and used it when I didn't want any item to be displayed. 我创建了一个空的透明图标,当我不想显示任何项目时使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM