javaswingjlabelgridbaglayoutminimum-size

I want a JLabel with a new getMinimumSize()


I want getMinimumSize to return weight=0 to cheat GridBagLayout.ipadx

I have tried:

  public class ImprovedLabel extends JLabel {
      @Override 
      public Dimension getMinimumSize() {
          return new Dimension(0, this.getHeight()); 
      } 
  }

But then, when I try:

ImprovedLabel overErrorLabel = new ImprovedLabel();
overErrorLabel.setText("Hello world!");

the label doesn't appear where it used to when it was a JLabel. It doesn't appear at all. I guess I'm doing the overrride wrong. Can I have some help?


Solution

  • The 0 width would make the JLabel invisible when the GUI is not large enough to show it fully.