Set margin for button group

Is there a way to jointly change the filling of JButtons? I found the setMargin () method, but this does not work in button groups, and I really can’t imagine that 25 buttons will be individual. :)

Thank!

+3
source share
3 answers

If your button group is called buttonGroup, you can use:

buttonGroup.getElements();

Returns Enumerationcontaining buttons. Then you can call setMargin()on each button ...

+2
source

:
1) .
2) JButtons "factory". , . 3) JButton ( ).
4) , ...

+1

If you want to do this for all buttons in an application, you can use UIManager:

UIManager.put("Button.margin", new Insets(10, 10, 10, 10) );

If you want to do this by specifying buttons in the application, you need to make each individual button. However, I do not understand the problem, since somewhere in your code you have to create 25 buttons. Thus, at this point you also set the margin on the button.

+1
source

Source: https://habr.com/ru/post/1788813/


All Articles