Article View: borland.public.jbuilder.java.language
Article #8808Re: How to change the default font and size on dialogs ???
From: Torsten Welches
Date: Wed, 28 Feb 2001 07:22
Date: Wed, 28 Feb 2001 07:22
43 lines
2489 bytes
2489 bytes
Asger,
unfortunately that is not as easy as you had expected.
1.
You create a JOptionPane instance and set it's font.
Then you call the static(!) showMessageDialog method which
returns an entirely new JOptionPane instance with the default
font.
2.
Even if it worked wouldn't you get what you want since setting
the pane's font does not automatically cause all containing
components to adopt that font. You want to change the font of
the message label, right?
3.
You can't directly control how the pane that showMessageDialog
returns looks like apart from the parameter argument options. It's ready-made, use it as it is or provide your own custom
MessageDialog.
4.
You *can* indirectly control how components are set up because
they get their font, color, border and so on from a list of ui
defaults. If you (temporarily) change that defaults you might
get want you want.
The defaults is a hashtable and is available through the
UIManager class: UIManager.getDefaults().
In your case:
UIDefaults uiDefaults = UIManager.getDefaults();
Font originalFont = uiDefaults.getFont("Label.font");
uiDefaults.put("Label.font", originalFont.deriveFont(30.0f));
JOptionPane.showMessageDialog(parent, "Test");
uiDefaults.put("Label.font", originalFont);//restore
5.
The UIDefaults are not documented and may change in a future
release. Consider tweaking them as a last ressort ;-)
You might be better off providing your own MessageDialog.
Torsten
Technical Details
Message-ID:
<3a9ca723$1_1@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!hermes.visi.com!news-out.visi.com!europa.netcrusader.net!205.252.116.205!howland.erols.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!207.105.83.65References:
<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-27 23:30:03 PST From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Subject: Re: How to change the default font and size on dialogs ??? Newsgroups: borland.public.jbuilder.java.language X-User-Info: 193.158.55.74 193.158.55.74 References: <3A9C17AE.403C957B@get2net.dk> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3a9ca723$1_1@dnews> Date: 27 Feb 2001 23:22:11 -0800 X-Trace: 27 Feb 2001 23:22:11 -0800, 207.105.83.65 Lines: 43 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!hermes.visi.com!news-out.visi.com!europa.netcrusader.net!205.252.116.205!howland.erols.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!207.105.83.65