Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show JLabel ellipsis in MigLayout?

Using the default layout manager, the JLabel shows its ellipsis when the frame is resized.

As illustrated by:

public static void main(String[] args) {
    final JFrame jFrame = new JFrame("JLabel, show me your ellipsis!");

    jFrame.getContentPane().add(new JLabel("Sure darling! Shrink me and I'll show you"));

    jFrame.pack();
    jFrame.setVisible(true);
}

However, MigLayout does not display such behaviour!

public static void main(String[] args) {
    final JFrame jFrame = new JFrame("JLabel, show me your ellipsis!");

    jFrame.getContentPane().setLayout(new MigLayout());
    jFrame.getContentPane().add(new JLabel("Nope! I just do not know you well enough!"));

    jFrame.pack();
    jFrame.setVisible(true);
}

I tried all the layout/component constraint I could think of. Does anybody know if such thing is even possible in Mig?

like image 620
Pigelvy Avatar asked Mar 25 '13 16:03

Pigelvy


1 Answers

A JLabel has a minimum size that is roughly (or exactly, don't remember) the same as its preferred size. MigLayout only shrinks a component down to its min. So you have to add a component constraint that allows sizing smaller than its minSize:

content.add(label, "wmin 10lp");
like image 149
kleopatra Avatar answered Sep 27 '22 22:09

kleopatra