Re: How to define a default font for JLabel or whole program?



On 15-4-2005 15:28, Chris wrote:

I don't really like how Java2 default font is bold.  I think the plain
looks much better.

How can I set the default font for a JLabel or for the whole program.
I would like to change it from BOLD to PLAIN.

About half of my JLabels in my program are anonymous.  It would quite a
pain to go and define a bunch of new JLabels, then change the font to
plain.

Use UIManager to define JLabel's default font

import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;

public class LabelFont {

   public static void main(String[] args) {
      Font oldLabelFont = UIManager.getFont("Label.font");
      UIManager.put("Label.font", oldLabelFont.deriveFont(Font.PLAIN));

      JFrame f = new JFrame("LabelFont Test");
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.getContentPane().setLayout(new FlowLayout());

      JLabel df = new JLabel("Default JLabel font");
      f.getContentPane().add(df);

      JLabel ef = new JLabel("Font explicitly set");
      ef.setFont(oldLabelFont);
      f.getContentPane().add(ef);

      f.pack();
      f.setVisible(true);
   }
}

--
Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \
.



Relevant Pages

  • How to define a default font for JLabel or whole program?
    ... I don't really like how Java2 default font is bold. ... How can I set the default font for a JLabel or for the whole program. ... I would like to change it from BOLD to PLAIN. ... About half of my JLabels in my program are anonymous. ...
    (comp.lang.java.help)
  • How to define a default font for JLabel or whole program?
    ... I don't really like how Java2 default font is bold. ... How can I set the default font for a JLabel or for the whole program. ... I would like to change it from BOLD to PLAIN. ... About half of my JLabels in my program are anonymous. ...
    (comp.lang.java.help)
  • Re: How to define a default font for JLabel or whole program?
    ... Roland wrote: ... How can I set the default font for a JLabel or for the whole program. ... I would like to change it from BOLD to PLAIN. ... About half of my JLabels in my program are anonymous. ...
    (comp.lang.java.help)
  • Re: Word applies direct format on File open
    ... I think what's happening here is that you have TNR defined as the default ... font for Plain Text, but the plain text is coming in with Courier New as ... the draft font. ... But the formatting toolbar nevertheless ...
    (microsoft.public.word.docmanagement)
  • Re: Word applies direct format on File open
    ... text indeed appears as TNR 12. ... the formatting toolbar changes and reports ... I think the issue here is that the formatting for the Plain Text style is ... you can check the box for "Draft font" on the View tab ...
    (microsoft.public.word.docmanagement)