Solved

Set font for InternalMessageDialog

Posted on 2011-02-14
6
303 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json example 39 130
Which is the latest version of Apache Tomcatl 3 49
starter POM and spring-boot-starter,  spring-boot-web 2 40
Apps blocked by Java 9 55
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

943 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

5 Experts available now in Live!

Get 1:1 Help Now