How to set java swing component size to its enclosing parent size. ex: setting JLabel size to its enclosing JPanel size.
Like android's Wrap_parent option.
How to set java swing component size to its enclosing parent size. ex: setting JLabel size to its enclosing JPanel size.
Like android's Wrap_parent option.
On the enclosing parent call .setLayout(new BorderLayout());
. The component in the center (default) cell of a BorderLayout
is forced to match the size of its container.
One way to go about it is to override doLayout() in the parent. In that method you can set the bounds of the label the way you like.