Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

another .ttf question

 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys i got another question on using the .ttf files. I want to leave the commented sections out. What i was trying to do was to set the fonts individually on the components but when i tried, it typed in teeny weeny size letters, and wasent even readable. Can anyone help me out. i just want to leave the code the way it is, but just be able to set the desired components to the imported font.

public Converter()
{
try{
InputStream in = Converter.class.getResourceAsStream("Augustin.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT,in);


c = new Conversions();
super.setLayout(new GridLayout(3,1));

label1 = new JLabel("Enter Fahrenheit:");
field1 = new JTextField(5);
field1.addActionListener(new FahrenheitListener());
button1 = new JButton("CONVERT");
button1.addActionListener(new FahrenheitListener());
label2 = new JLabel("to Celsius:");
field2 = new JTextField(8);
field2.setEditable(false);
panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
panel1.add(label1);
panel1.add(field1);
panel1.add(button1);
panel1.add(label2);
panel1.add(field2);
add(panel1);

label3 = new JLabel("Enter Celsius:");
field3 = new JTextField(5);
field3.addActionListener(new CelsiusListener());
button2 = new JButton("CONVERT");
button2.addActionListener(new CelsiusListener());
label4 = new JLabel("to Fahrenheit:");
field4 = new JTextField(8);
field4.setEditable(false);
panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
panel2.add(label3);
panel2.add(field3);
panel2.add(button2);
panel2.add(label4);
panel2.add(field4);
add(panel2);

button3 = new JButton("CLEAR");
button3.addActionListener(new button3Listener());

button4 = new JButton("CHANGE BACKGROUND COLOR");
button4.addActionListener(new button4Listener());

button5 = new JButton("EXIT");
button5.addActionListener(new button5Listener());

panel3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
panel3.add(button4);
panel3.add(button3);
panel3.add(button5);
add(panel3);
}catch(Exception ex){ex.printStackTrace();}
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you're asking -- what do you mean by "I want to leave the commented sections out"? Anyway, you mentioned teeny fonts. I think that's because the following line:

Font font = Font.createFont(Font.TRUETYPE_FONT,in);

creates a font of size 1!!! Luckily, it's easy to derive a font with a different size:

Font font12 = font.deriveFont((float)12);

Be careful -- methods deriveFont(int) and deriveFont(float) are very different!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic