简体   繁体   English

如何更改JOptionPane的字体大小

[英]how to change font size of 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");     

}
}

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. 我的问题是,我可以更改我的JOptionPane的字体大小和样式,使我的列表字体更大,非常感谢任何提示。 Thanks. 谢谢。

If you want all JOptionPane s to have the same font style and size, you can change the property of the UIManager with: 如果您希望所有JOptionPane具有相同的字体样式和大小,您可以使用以下命令更改UIManager的属性:

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]);
}

One of the easiest ways is to use HTML directly in the String literal. 最简单的方法之一是直接在String文字中使用HTML。 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. 请注意,使用HTML时,您不能再使用\\n表示新行。 Use <br> instead. <br>来代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM