如何更改JOptionPane的字体大小 [英] how to change font size of JOptionPane

查看:172
本文介绍了如何更改JOptionPane的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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");     

}
}

这些是我上面的代码.我的问题是,我可以更改JOptionPane的字体大小和样式以使列表字体变大吗,非常感谢任何提示.谢谢.

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.

推荐答案

如果希望所有JOptionPane具有相同的字体样式和大小,则可以使用以下方法更改UIManager的属性:

If you want all JOptionPanes 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]);
}

这篇关于如何更改JOptionPane的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆