Results 1 to 5 of 5
  1. #1
    fletcher is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default Changing the default fonts via UIManager

    Java Code:
    public static void main(String[] args) {
            try {
                // Set System L&F
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (UnsupportedLookAndFeelException e) {
                System.out.println("unsupported look and feel exception");
            } catch (ClassNotFoundException e) {
                System.out.println("Class not found");
            } catch (InstantiationException e) {
                System.out.println("instantiation exception");
            } catch (IllegalAccessException e) {
                System.out.println("illegal access exception");
            }
    
            Font defaultFont = new Font("Arial",Font.PLAIN,12);
            UIManager.put("Label.font", defaultFont);
    
            ...
    My system look and feel is gtk. The default font is hideous. I have changed it on my system so I never see it, but Java still uses it. As far as I can tell this should work (to change the JLabel's), but it doesn't seem to have any effect.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    What happens for other LAFs? Maybe GTK doesn't use the UIManager.

  3. #3
    fletcher is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by camickr View Post
    What happens for other LAFs? Maybe GTK doesn't use the UIManager.
    When I remove the .setLookAndFeel() method, it works. Does this mean I cannot use this method to set a default font? Do I have to go through my program label by label?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Does this mean I cannot use this method to set a default font? Do I have to go through my program label by label?
    I guess. I don't know how the LAF works. You can try the UIManager Defaults program to see if it list any UIDefaults for the GTK LAF:

    tips4java.wordpress.com/2008/10/09/uimanager-defaults/

    If not, then maybe the LAF itself has some methods that allow you to customize it.

  5. #5
    fletcher is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Apparently the look and feel ignores the UIManager font altogether. I checked using the program you linked and my own code. The default is reading as "MS Sans Serif" (which is the font I set as my system default--I know, sacrilege, but it's a nice font). The look and feel uses something else, I believe the default linux font (can't remember what it's called).

Similar Threads

  1. Changing default Applet Viewer Size?
    By dsym@comcast.net in forum Java Applets
    Replies: 6
    Last Post: 08-27-2010, 07:42 PM
  2. Fonts (Changing Fonts and Color's)
    By dbashby in forum New To Java
    Replies: 10
    Last Post: 04-06-2009, 02:32 AM
  3. how to get raw image data for fonts
    By Nicholas Jordan in forum Java 2D
    Replies: 8
    Last Post: 04-05-2009, 07:15 AM
  4. Replies: 1
    Last Post: 03-10-2009, 02:12 PM
  5. Swing - Changing component default font
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •