日期:2014-05-20 浏览次数:20818 次
import java.awt.BorderLayout; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; /** * Implements to get the font type. * @author Wind */ public class TestFont extends JFrame{ private static final long serialVersionUID = 1L; JLabel lblTest = new JLabel("test"); JPanel pnlMain = new JPanel(); public TestFont(){ lblTest.setFont(new Font(Font.DIALOG, Font.BOLD, 12)); pnlMain.setLayout(new BorderLayout()); pnlMain.add(lblTest, BorderLayout.CENTER); this.add(pnlMain); printFontType(); } private void printFontType(){ System.out.println(lblTest.getFont().getFontName()); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub TestFont t = new TestFont(); t.setSize(300, 200); t.setLocation(300, 200); t.setVisible(true); } }
------解决方案--------------------
String str=String.valueOf(BOLD);