Solved

Set font for InternalMessageDialog

Posted on 2011-02-14
6
306 Views
Last Modified: 2012-06-27
I am using InternalMessageDialog in my application.How can i set font for the same.

I am pasting the code below-

javax.swing.JOptionPane.showInternalMessageDialog(this.getParent(),"Please Enter City","Information Message",javax.swing.JOptionPane.INFORMATION_MESSAGE);
               
0
Comment
Question by:Aurii
  • 2
  • 2
  • 2
6 Comments
 
LVL 26

Accepted Solution

by:
ksivananth earned 250 total points
ID: 34894454
try this,

JLabel l1 = new JLabel("Please Enter City"),
   l1.setFont( new Font(font, Font.PLAIN, 16) );
JPanel p = new JPanel();
   p.add(l1);
javax.swing.JOptionPane.showInternalMessageDialog(this.getParent(), p,"Information Message",javax.swing.JOptionPane.INFORMATION_MESSAGE);


0
 

Author Comment

by:Aurii
ID: 34894551
It works for msg ..but how to change the font of  the "OK"  button now ..
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34894790
This code changes
the font of the button

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import java.awt.*;

public class ConfigOptionPaneLanguage {
  public static void main(final String[] args) {
//
  
    Font font = new Font("Dialog", Font.BOLD,20);
    UIManager.put("OptionPane.buttonFont", font);   

    JFrame parent = new JFrame();


    String multiLineMsg[] = { "Hello,", "World"} ;
    JOptionPane.showMessageDialog(parent, multiLineMsg);
  }
}

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Aurii
ID: 34895947
Sorry, but I am not getting this code. How to apply it in my code?
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 34896064
that changes the font for all option pane instance you open in your app, not sure if thats what you want!

if not, better create your own dialog!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34899051
Perhaps you can set it when you create some Option panes
and then set it to another font at another time
if you post your piece of code, pmaybe we could figure out how
to use it in your particular situation.
I ran this particular program and saw that it works.

Now I ran the code below and it first showed me pane
with big font and then showed me next option pane
with smalle font

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import java.awt.*;

public class ConfigOptionPaneLanguage {
  public static void main(final String[] args) {
//
  
    Font font = new Font("Dialog", Font.BOLD,20);
   Font font1 = new Font("Dialog", Font.BOLD,12);
    UIManager.put("OptionPane.buttonFont", font);   

    JFrame parent = new JFrame();


    String multiLineMsg[] = { "Hello,", "World"} ;
    JOptionPane.showMessageDialog(parent, multiLineMsg);

       UIManager.put("OptionPane.buttonFont", font1);
        JOptionPane.showMessageDialog(parent, multiLineMsg);



  }
}

Open in new window


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question