IAmYourFaja
IAmYourFaja

Reputation: 56912

Why do Swing JButtons truncate?

Swing newbie here. I used the NetBeans built-in GUI build to make an applicaton with a menu and some JDialogs. On some (not all) of the JDialogs, the labels of the JButtons are truncated. For instance, if a JButton label should read Create, I'll see Creat.... Even when I resize the window the buttons don't resize and show the entire label.

What does SO recommend? Are there special settings in NB that I have to configure in order to force the application to show the whole label? Thanks in advance.

Upvotes: 1

Views: 508

Answers (2)

trashgod
trashgod

Reputation: 205795

You may be violating the button's preferred size through incorrect use of the enclosing panel's layout. The GUI designer may obscure the problem. Several related caveats are discussed here.

Also consider creating an sscce that exhibits the problem you describe.

Addendum: As concrete examples, each ButtonPanel has a default FlowLayout, which allows each button to adopt its preferred size. By comparison, the buttons in this ButtonIconTest adopt the preferred size of the specified icons.

Upvotes: 3

Allen Z.
Allen Z.

Reputation: 1588

You (or Netbeans) is probably setting the preferred width of the JLabel.

If possible, use another Layout: http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html.

If that is not practical, you can also manually specify your desired button width

label.setMinimumSize(size);
label.setPreferredSize(size);

as long as you will not change the font.

Upvotes: -2

Related Questions