Welcome, Guest. Please login or register.

Author Topic: JAVA global font setting  (Read 1746 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline toRus

  • Full Member
  • ***
  • Join Date: Mar 2003
  • Posts: 122
    • Show all replies
Re: JAVA global font setting
« on: May 21, 2004, 12:46:51 AM »
JDialog is a container. You should add a JLabel to its ContentPane. You are free to change the JLabel's font:
e.g.

Code: [Select]

import javax.swing.*;
import java.awt.*;

public class MyDialog
{
  public static void main(String[] args)
  {
    JFrame frame = new JFrame(); //owner        
    JDialog dialog = new JDialog(frame,"My Dialog");
    dialog.pack();
    dialog.setSize(320,240);    
    JLabel label = new JLabel("Hello world");
    label.setFont(new Font("MonoSpace",Font.ITALIC,20));
    dialog.getContentPane().add(label);    
    dialog.setVisible(true);
  }
}


Instead of adding the JLabel directly you could/should add it to a JPanel first, etc...


Regarding font global settings, the fonts are set by the LookAndFeel (L&F). You should create a custom LookAndFeel (or customise an existing one) class and define your preferred font settings for every item there using something like this e.g.

Code: [Select]

UIManager.put("Menu.font", new FontUIResource(yourFont));


(ditto for Button.font, Tree.font, CheckBox.font, etc.)


You can then use the created L&F in your code:
Code: [Select]

UIManager.setLookAndFeel(yourLookAndFeelClass);


or specify it at command line:
Code: [Select]

java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel YourApp


or change the contents (you might have to create it if it does not exist) of the file $JAVA_HOME/lib/swing.properties :
Code: [Select]

#swing.properties
swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel


Alternatively, you might want to have a look at the contents of $JRE_HOME/lib/font.properties .

Look here,  here and here for more details.


 

Offline toRus

  • Full Member
  • ***
  • Join Date: Mar 2003
  • Posts: 122
    • Show all replies
Re: JAVA global font setting
« Reply #1 on: May 22, 2004, 01:30:09 PM »
:-)