Solved

Label on JButton is too small

Posted on 2004-10-01
10
1,171 Views
Last Modified: 2012-06-21

In the following code I display 4 buttons. When I run it, the two smaller buttons display 3 boxes which I think is equivalent to three dots meaning there isn't enough room to display the text. The two larger buttons display my tiny little symbol (which is a solid black triangle) correctly.

Looking at the two smaller buttons there is obviously plenty of room to display this tiny symbol. The three boxes being displayed instead are way larger.

Can anyone see what I'm doing wrong? Can I increase the size of the button label without increasing the size of the button? Or maybe there is some way to tell java to just display the string without displaying three dots if it thinks it doesn't fit?

I don't know if this problem is related to the font itself but Webdings is a standard font on Windows 98/2000/ME/XP which is where I'll be running this code.

Here is an example. Thanks for looking!

package testwebdings;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class TestWebDing {
   
    public static void main(String[] args) {
        new TestWebDing();
    }
   
    TestWebDing()
    {
    Font dingFont8 = new Font("webdings",Font.PLAIN,8);
    String upTriangle = (new String(new char[]{(char)0xf035}));
    //
    JButton button30 = new JButton(upTriangle);
    JButton button40 = new JButton(upTriangle);
    JButton button50 = new JButton(upTriangle);
    JButton button60 = new JButton(upTriangle);
    //
    button30.setPreferredSize(new Dimension(30,30));
    button40.setPreferredSize(new Dimension(40,40));
    button50.setPreferredSize(new Dimension(50,50));
    button60.setPreferredSize(new Dimension(60,60));
    //
    button30.setFont(dingFont8);
    button40.setFont(dingFont8);
    button50.setFont(dingFont8);
    button60.setFont(dingFont8);
    //
    JFrame controlFrame = new JFrame("Test WebDings");
    Container content = controlFrame.getContentPane();
    JPanel panel = new JPanel(new FlowLayout());
    content.add(panel);
    //
    panel.add(button30);
    panel.add(button40);    
    panel.add(button50);
    panel.add(button60);
    //
    controlFrame.setBounds(0,0,400,100);
    controlFrame.setVisible(true);
    } // end ctor
} // end class
0
Comment
Question by:adg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12206240
the 3 boxes sound more like that font doesn't have a defined symbol for the that character.
Check you are using the right character(s).
0
 
LVL 92

Expert Comment

by:objects
ID: 12206248
or it could be the font doesn't have a symbol for the "." (indicating not enough room).
try increasing the preferred size for the button
0
 
LVL 3

Author Comment

by:adg
ID: 12206259
>> the 3 boxes sound more like that font doesn't have a defined symbol for the that character.
Check you are using the right character(s).

I know it is defined because it shows up on the two larger boxes.

>> or it could be the font doesn't have a symbol for the "." (indicating not enough room).
try increasing the preferred size for the button

Yes, that is exactly right - it is the period which is not defined. But I don't want to make the button bigger. There seems to be plenty of room, the symbol is very small, much smaller than the three boxes that are being displayed.



0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 92

Expert Comment

by:objects
ID: 12206260
or make the font size smaller
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 12206265
using a border that uses les space (or no border at all) may also give you some more space

button30.setBorder(null);
0
 
LVL 3

Author Comment

by:adg
ID: 12206297
>> button30.setBorder(null);

That was interesting - apparently it is related to the border, now the symbols are showing up, even when I make them normal size which is good. The only problem is I don't have buttons anymore, just the symbols hanging in mid-frame! Is there some way to have a border without having it take up so much room? Or perhaps there is another way to clue the user that this is a button?

BTW, thanks for your help so far. I think that border comment was a mjor breakthrough.
0
 
LVL 3

Author Comment

by:adg
ID: 12206331
It didn't occur to me to mention it before but I'm using the windows look and feel. I'm now trying to figure out how to turn it off and see if that helps.

Also, I found this in reference to a similar sounding (but not the same) bug.

"You can manually set the toolbar border to use a compound border, where the inner border is empty and is set to use the
appropriate top,left,bottom,right padding"

I'm trying to figure out what that means. Is that something that could apply to a JButton?
0
 
LVL 3

Author Comment

by:adg
ID: 12206418
OK, I finally changed to the motif plaf and the button sizing is much more rational so I think this might be a bug in the windows plaf.

Anyway, I'm going to try to figure out this compound border idea since I really do need the windows plaf.
0
 
LVL 3

Author Comment

by:adg
ID: 12206448
This worked!

    Border bb = button30.getBorder();
    EmptyBorder eb = new EmptyBorder(-20,-20,-20,-20);
    CompoundBorder cb = new CompoundBorder(bb,eb);    
    button30.setBorder(cb);  

Thanks for pointing out the border!
0
 
LVL 92

Expert Comment

by:objects
ID: 12209189
no worries :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 74
How do I remove an object from a 3 53
wild fly 8 startup error 2 43
Java array 21 87
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question