mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

Problems about settings bounds of the components #626

Closed UltraBurstXD closed 4 years ago

UltraBurstXD commented 4 years ago

Hello Mgarin,

I'm having problems setting the bounds of WebButton component. I'm trying to use the convenient way - setBounds(), to no avail. It fills the whole panel. Is there a another method that I'm missing?

mgarin commented 4 years ago

You can set bounds of the component in container only when it doesn't have a layout (has a null layout). Panels do have a layout by default - BorderLayout in case of WebLaF - that is why your button fills the whole panel size and ignores your bounds.

To position components it is recommended to use layout managers that are available in Swing and many 3rd-party libraries. I recommend checking official tutorial on layout managers here: https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html

You can also create your own layout manager (although usually it is not needed as existing ones already cover most possible use cases) to dynamically update positioning of the components on the container as it's size changes or components get added or removed from it.

UltraBurstXD commented 4 years ago

Understood, thanks for the help.