Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default Font

 
Helmut Lerch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy all,

suppose the following Code:
<pre>
import java.awt.*;
public class TestFonts {
public static void main (String[] args) {
Frame f = new Frame();
Button bt = new Button();
f.add(bt);
System.out.println(bt.getFont());
}
}
</pre>
The Output is "null".



My Questions:

1.) When is a Font assigned to a Component if we don't use setFont(Font f)?

2.) Which "default" Font is used by a Component if we don't assign a Font to a Component by using setFont(Font f)? (And how can we get it?)

Thanks for help.
 
MSD
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You are right. The output is null.
A font is assigned to a component when it first becomes visible. Since you never made the button visible, the font returned was null. Just add the following before System.out.println and it should work :

The default font for a component is picked up from system. On mine it is "dialog" (ie san serif), styl plain, size 12.
Hope this helps,
Mohammed
Originally posted by Helmut Lerch:
Hy all,

suppose the following Code:
<pre>
import java.awt.*;
public class TestFonts {
public static void main (String[] args) {
Frame f = new Frame();
Button bt = new Button();
f.add(bt);
System.out.println(bt.getFont());
}
}
</pre>
The Output is "null".



My Questions:

1.) When is a Font assigned to a Component if we don't use setFont(Font f)?

2.) Which "default" Font is used by a Component if we don't assign a Font to a Component by using setFont(Font f)? (And how can we get it?)

Thanks for help.

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

not to be picky but,
when you don't use setFont() on a component, the component
will inherit the font of its parent. Eventually, we may endup
picking it up from the default system font.
regds.
- satya
 
Helmut Lerch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying.
Originally posted by Madhav Lakkapragada:
Eventually, we may endup
picking it up from the default system font.
- satya[/B]

And where can I get this font before setVisible(true)?
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic