Solved

Set font for InternalMessageDialog

Posted on 2011-02-14
6
304 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

803 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