While working on something related on using this class, i found this piece of code:
public Dimension getPreferredSize() {
Dimension size;
if (this.getText() == null || this.getText().isEmpty()) {
setText( " " );
size = super.getPreferredSize();
setText( "" );
}
else {
size = super.getPreferredSize();
}
return size;
}
I do understand that this class is a JLabel and can use labels for rendering. But why is being initialized (in case is not) during this getter? Wouldn't make more sense on just doing it on the constructor?
By reading the source code
you can see a comment explaining such behavior: