how to change font size of JOptionPane

前端 未结 2 1332
余生分开走
余生分开走 2021-01-25 19:53
import java.awt.ComponentOrientation;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing         


        
相关标签:
2条回答
  • 2021-01-25 20:35

    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]);
    }
    
    0 讨论(0)
  • 2021-01-25 20:41

    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.

    0 讨论(0)
提交回复
热议问题