How to center elements in the BoxLayout using center of the element?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-04-01T13:49:06Z Indexed on 2010/04/01 13:53 UTC
Read the original article Hit count: 210

Filed under:
|
|
|
|

I use outputPanel.setLayout(new BoxLayout(outputPanel, BoxLayout.Y_AXIS)); and then I add elements (for example JLabels, JButtons) to the outputPanel. For example: outputPanel.add(submitButton);.

I see that all added elements are "centered". It is good, because I do want my elements to be in the center. When I write "center" I mean "equal distance from left and right". But the problem is that the left part of the element is put into the center. And I want to have center of elements to be put into the center. How can I get this behavior?

© Stack Overflow or respective owner

Related posts about java

Related posts about swing