Hi, I have over 10 JRadio Buttons and there are some properties they all have in common, so instead of writing these properties one by one to each radio button, is there are way to set them once for all?
The properties I want to set for all radio buttons are:
radiButtonName.setOpaque(false);
radiButtonName.setContentAreaFilled(false);
radiButtonName.setBorderPainted(false);
radiButtonName.setBorder(null);
I tried using UIManager but it's acting strange and it doesn't support all of the properties i require.
I would like to avoid creating additional class and extend radio button. Because I would also like to apply this technique to other components to reduce the code written, this will make the code much shorter. Thank you in advance :)
If you have to do the same thing a N number of time try to write a method that will do the trick for you :)
So the problem here is to set up 10 JRadioButton ? You could create a method returning a list (or annother collection/maps/...) of JRadio button like the following :
private List<JRadioButton> setUpButtons() {
//create list
for(int i = 0; i < NB_BUTTONS; i++) {
//set the properties wanted
}
return myList;
}
Note that the NB_BUTTONS is a variable like that :
private final int NB_BUTTONS = 10;
It's easier to modify the value once than modify it in all your code. With the same logic you could write a method 'preparing' one JRadioButton. It depends on how you want to do the things that you want to do.