#Buttons are not same size in Java Swing
11 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @junior imp! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
maybe your width is too small?
i mean that wouldnt make any sense tho, since length of the panel is 200
Prefer to set the preferredSize rather than the size. The entire point of a layout manager is to delegate sizing to it. For that it will try its best to honor preferred dimensions
BoxLayout honors the maximum size not the preferred size.
For a top-to-bottom box layout, the preferred width of the container is that of the maximum preferred width of the children. If the container is forced to be wider than that, BoxLayout attempts to size the width of each component to that of the container's width (minus insets). If the maximum size of a component is smaller than the width of the container, then X alignment comes into play.
see https://docs.oracle.com/javase/tutorial/uiswing/layout/box.html#:~:text=For a top,comes into play