Is there a way to set, when specifying height and width of a component in Swing, that a given object should fill the available vertical/horizontal space? I.e. I would like to say setSize(*, 100) to allow horizontal fill.
Is there a way to set, when specifying height and width of a component
Share
You can call
setSizewith whatever you want, but in the end it is theLayoutManagerof the parentContainerwhich decides what position and what size each component gets.So by using the correct
LayoutManageryou can typically succeed in letting a component take all the available width.As you can see in the
BorderLayoutpart of the Visual guide to LayoutManagers tutorial thePAGE_STARTandPAGE_ENDtake all the available width.By specifying the height as preferred size you will obtain the desired result