简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM