现在在写一个程序,想根据变更窗口标题栏的字体类型。
这个窗口类继承自JFrame
可是我还是没有找到合适的方法,我使用了UIManager.put()方法设置了"InternalFrame.titleFont",InternalFrameTitlePane.font","OptionPane.font",但是出现的提示信息框和窗口的标题栏字体仍然为默认字体,不知道如何修改才能使标题栏的字体改变,希望各位大侠指点迷津,谢谢。下面是我的代码。
package messageDialog;import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.plaf.*;public class MessageDialog extends JFrame {
public MessageDialog(String title)
{
  super(title);
  this.getContentPane().setBackground(Color.gray);
 }
public Font getFont()
{
 return UIManager.getFont("InternalFrameTitlePane.font");
}
       public void changeColor(Color targetColor, String colorName)
      {
       JOptionPane.showMessageDialog(this,"Press OK to change the background color to " + colorName);
      this.getContentPane().setBackground(targetColor);
      this.getContentPane().repaint();
      }
       
    public static void main(String[] args)
    {
      UIManager.put("Button.font",new FontUIResource("宋体",0,12));
      UIManager.put("Label.font",new FontUIResource("宋体",0,12));
      UIManager.put("JRootPane.font",new FontUIResource("宋体",0,12));
      UIManager.put("InternalFrame.titleFont",new Font("宋体",Font.ITALIC,12));
      UIManager.put("OptionPane.font", new FontUIResource("宋体",Font.ITALIC,12));
      MessageDialog f = new MessageDialog("消息框");
      
      //f.getContentPane().setFont(new Font("宋体",1,12));
      f.setSize(200, 200);
      f.setLocation(100,100);
      f.addWindowListener(new WindowAdapter()
      {
     public void windowClosing(WindowEvent evt)
     {
      System.exit(0);
     }
      });
      f.setVisible(true);
      f.changeColor(Color.RED,"red");
      f.changeColor(Color.YELLOW,"yellow");
    }
}