tags:

views:

52

answers:

3

Hello,

Sorry for the odd choice of words for the title, however, "border" seems to be the inappropriate term. 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.

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. 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).

Any suggestions? Am I going to have to create a custom renderer? I will be looking at that in the mean time.

+1  A: 

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.

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.

Steve Gilham
A: 

You have to choices here:

1) Customize Look and Feel as described in previous entry.

2) Create your own custom controls by inheriting from existing ones and overriding component painting.

eugener
A: 

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.

Todd