Roman Rdgz
Roman Rdgz

Reputation: 13264

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?

Upvotes: 1

Views: 110

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168845

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

Upvotes: 1

Related Questions