Reputation: 31
import java.awt.ComponentOrientation;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
public class trial2
{
public static void main(String[] args)
{
String[] option = {"Chorita M. Adlawan", "Noel B. Angeles", "Julie P. Benenoso", "Percival P.Bermas",
"Beverly Mae M. Brebante","Adela N. Cabaylo", "Carol G. Cainglet", "Oscar U. Cainglet",
String selected = (String)JOptionPane.showInputDialog(null, "MINES AND GEOSCIENCES BUREAU - REGION XI, DAVAO CITY\n" +
" LIST OF REGISTERED EMPLOYEES",
"Please Select Employee",JOptionPane.DEFAULT_OPTION, null, option , "Adlawan");
}
}
Those are my codes above. My question is, can i change the font size and style of my JOptionPane to make my list font larger, very much appreciated for any tip. Thanks.
Upvotes: 1
Views: 10748
Reputation: 16403
If you want all JOptionPane
s to have the same font style and size, you can change the property of the UIManager
with:
javax.swing.UIManager.put("OptionPane.font", new Font("yourFontName", Font.BOLD, 30));
To get a list of the available font names, use the following snippet:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontNames = ge.getAvailableFontFamilyNames();
for (int index = 0; index < fontNames.length; index++)
{
System.out.println(fontNames[index]);
}
Upvotes: 3
Reputation: 2549
One of the easiest ways is to use HTML directly in the String literal. For example:
"MINES AND GEOSCIENCES BUREAU - REGION XI, DAVAO CITY\n"
Can easily become:
"<html><span style='font-size:2em'>MINES AND GEOSCIENCES BUREAU - REGION XI, DAVAO CITY"
Note that when you use HTML, you can no longer use \n
for new lines. Use <br>
instead.
Upvotes: 1