Solved

Set font for InternalMessageDialog

Posted on 2011-02-14
6
302 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now