how to change font size of JOptionPane

若如初见. 提交于 2019-12-02 03:59:58
halex

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!