Link to home
Start Free TrialLog in
Avatar of liljegren
liljegrenFlag for Sweden

asked on

Swing: Font is too small

In one Swing app I use this line:

  textArea.setFont(new Font("MonoSpaced", Font.PLAIN, 10));

I expected something like Courier New, 10 pt in Windows, but I get a very small monospaced font. I think it's 7pt because when I write 13 instead of 10, I get 10...

Why is this and can it be solved?
Avatar of Ovi
Ovi

Don't set directly the font like you have done allready. Create an Font object and work a little on him, and only after that set'it. ...or just set the apropiate value to you GUI style.
Here is a suggested example from Sun.


public class LabelPanel extends JPanel {
  public LabelPanel() {
    // Create and add a JLabel
    JLabel plainLabel = new JLabel("Plain Small Label");
    add(plainLabel);
    // Create a 2nd JLabel
    JLabel fancyLabel = new JLabel("Fancy Big Label");
    // Instantiate a Font object to use for the label
    Font fancyFont =
      new Font("Serif", Font.BOLD | Font.ITALIC, 32);
    // Associate the font with the label
    fancyLabel.setFont(fancyFont);
    // Create an Icon
    Icon tigerIcon = new ImageIcon("SmallTiger.gif");
    // Place the Icon in the label
    fancyLabel.setIcon(tigerIcon);
    // Align the text to the right of the Icon
    fancyLabel.setHorizontalAlignment(JLabel.RIGHT);
    // Add to panel
    add(fancyLabel);
  }
}

ASKER CERTIFIED SOLUTION
Avatar of vladi21
vladi21

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial