#Buttons are not same size in Java Swing

11 messages · Page 1 of 1 (latest)

junior imp
#

ive got these 3 buttons, i want to be same width but they arent, any idea why? ive also tried the preffered size but no result

delicate bluffBOT
#

This post has been reserved for your question.

Hey @junior imp! Please use /close or the Close Post button 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.

twin laurel
#

maybe your width is too small?

junior imp
#

i mean that wouldnt make any sense tho, since length of the panel is 200

steep yew
#

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

pastel haven
#

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

wise cargo
#

Or If you want a stupid solution just add invisible/small characters to the buttons text

#

Im lazy i would probably do that

#

But i reccomend working with the layout manager