liljegren
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?
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?
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(fancyFo nt);
// Create an Icon
Icon tigerIcon = new ImageIcon("SmallTiger.gif" );
// Place the Icon in the label
fancyLabel.setIcon(tigerIc on);
// Align the text to the right of the Icon
fancyLabel.setHorizontalAl ignment(JL abel.RIGHT );
// Add to panel
add(fancyLabel);
}
}
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(fancyFo
// Create an Icon
Icon tigerIcon = new ImageIcon("SmallTiger.gif"
// Place the Icon in the label
fancyLabel.setIcon(tigerIc
// Align the text to the right of the Icon
fancyLabel.setHorizontalAl
// Add to panel
add(fancyLabel);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.