🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8809

Re: How to change the default font and size on dialogs ???

#8809
From: John McGrath TeamB
Date: Wed, 28 Feb 2001 09:13
74 lines
3780 bytes
On Tue, 27 Feb 2001 22:10:07 +0100, Asger Joergensen wrote:

> As i say in the headline i want to change the size and
> font of the default dialogs. And comming from BC++B
> I thought that the below code would do the trick or at
> least change the font size in the dialog, but nothing
> happens.


>   JOptionPane Pane = new JOptionPane();
      :
>   Pane.setFont(NewFont);

You are setting the font for the JOptionPane, but the JOptionPane 
consists of many different components (JLabels, JButtons, etc.), and 
each of these components has its own default font.

You could traverse the component hierarchy, and set the font for all of 
the components that you find.  I think all of the default fonts for the 
JOptionPane components (for the standard look-and-feels) are 12-point 
Plain Dialog fonts, so you could probably set the same font for all 
components that you find.

If you are looking to change the fonts for all GUI components, you 
might take a look at the UIDefaults class.  This is essentially a hash 
table that Swing uses to get the default resources for all components 
it creates.  You can set the default font for individual components 
using code like this, called once before you start creating GUI 
components:

    UIDefaults defaults = UIManager.getDefaults();

    defaults.put( "Button.font",
        new Font( "dialog", Font.PLAIN, 16 ) );

    defaults.put( "ToggleButton.font",
        new Font( "dialog", Font.PLAIN, 16 ) );

A more general way of doing this would be to scan the UIDefaults table, 
and replace any font you find with a larger version of the same font.  
You could do this with code that looks something like this.

   void adjustFontSize( int adjustment ) {
      UIDefaults defaults = UIManager.getDefaults();
      Vector newDefaults = new Vector();
      for ( Enumeration e = defaults.keys(); e.hasMoreElements();  ) {
         Object key = e.nextElement();
         Object value = defaults.get( key );
         if ( value instanceof Font ) {
            Font oldFont = (Font) value;
            Font newFont = new Font( oldFont.getName(),
               oldFont.getStyle(), oldFont.getSize() + adjustment );
            newDefaults.add( key );
            newDefaults.add( newFont );
         }
      }

      defaults.putDefaults( newDefaults.toArray() );
   }

I have not run this code, so there may be errors in it, but I think it 
should be more or less correct.  If you do this, you might want to 
change the code to only create one copy of each font.  Many of the 
entries in the table will have the same value, so this would cut down 
on the number of Font objects you create.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.15067fcac0176786989fda@forums.borland.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!news.tele.dk!193.251.151.101!opentransit.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mail
References: <3A9C17AE.403C957B@get2net.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,dafba69d262afba3
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-02-28 01:18:07 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!news.tele.dk!193.251.151.101!opentransit.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!not-for-mail
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: How to change the default font and size on dialogs ???
Date: Wed, 28 Feb 2001 04:13:46 -0500
Organization: Another Netscape Collabra Server User
Lines: 74
Message-ID: <MPG.15067fcac0176786989fda@forums.borland.com>
References: <3A9C17AE.403C957B@get2net.dk>
NNTP-Posting-Host: dslcv1-60.fast.net
X-Newsreader: MicroPlanet Gravity v2.30