I would like to create a set of buttons in a Java Swing application, as in a typical tool palette in a drawing program. That is, a set of small square buttons, each of which contains an icon, only one of which is pressed, and when you press another button, the first is not selected. I thought of a number of solutions, and none of them seem very light / elegant.
This seems to work for JRadioButton, but if you add an icon to it, you will still get a small circle that is pretty inefficient. I guess the option would be to find alternative Look and Feel or Paint code for JRadioButton.
Another alternative would be to add a JButton to the ButtonGroup, perhaps setting the JToggleButton.ToggleButtonModel model as a model, but this does not have the desired effect, since the drawing code for the standard JButton does not leave it pressed when selected. Perhaps the JButton code might be changed for this. Just like drawing is โselectedโ just like โpressingโ.
A third alternative would be to use regular JButton and add a regular mouse listener that holds them pressed or not, and passes the changes between the buttons.
Can someone advise a better way to achieve the goal, please? A simple method that I skipped would be better, but advice on which of these three alternatives would be the best, and pointers on how to get started would also be helpful.