File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to change the font of JOptionPane? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to change the font of JOptionPane?" Watch "How to change the font of JOptionPane?" New topic
Author

How to change the font of JOptionPane?

Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Hi,
I want to change the font of buttons in JOptionPane, can you help me?
Best,
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Try this :
Font txtFont = new Font("Monospaced", Font.PLAIN,11);
myJButton.setFont(txtFont);
Hope it helps...


humanum errare est.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I wasn't sure if OptionPane.getOptions() returned an array of the buttons, or just the Strings, but when I tested it, it just returns 'null' unless you specifically set options yourself. You could get buttons from the BasicOptionPaneUI, but the method is protected, so it would be a pain to re-implement the entire OptionPaneUI just to get to this. You could also create your own buttons with the specified font, and pass them into the optionpane constructor as 'options' but then you'd have to implement the actionlisteners that should be attached to the buttons (option pane doesn't do this for you).

You could use a method like the following to get all the buttons, then go through the list and set the font on each one. This is really just hack (unfortunately though, I don't see a *good* way to do this). Pass the JButton.class class in and the option pane (or dialog, or internal frame created from the option pane). Then just go through the list you get back and call setFont() on each button.



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Bigwood Liu
Ranch Hand

Joined: Feb 26, 2003
Posts: 240
Thank you Nathan, I think a better way is to create my own dialog.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to change the font of JOptionPane?
 
Similar Threads
JOptionPane
Setting custom font JOptionPane
Changing the color of a String...
How can I change the font of JOptionPane?
java alert