更改整个JFrame的字体类型和大小?

Ank*_*kit 1 java fonts swing jpanel jframe

我正在研究Java GUI项目.我在基于swing的GUI上有几个组件.我想更改所有组件的字体设置,而不是逐个更改每个组件的字体.

有没有办法在JFrame上更改JPanel上所有组件的字体类型和大小.

编辑:

这是我的代码的样子:

public class Test extends JFrame{
   public Test(){

     //all components are initialized here. (some buttons and text fields) and added to this
      this.setVisible(true);
   }

   public static void main(String []args){
     new Test();
   } 

}
Run Code Online (Sandbox Code Playgroud)

Eng*_*uad 5

public static void setUIFont(javax.swing.plaf.FontUIResource f)
{   
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while(keys.hasMoreElements())
    {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if(value instanceof javax.swing.plaf.FontUIResource) UIManager.put(key, f);
    }
}

// ...

try
{
    setUIFont(new javax.swing.plaf.FontUIResource("Tahoma",Font.PLAIN,12));
}
catch(Exception e){}
Run Code Online (Sandbox Code Playgroud)

PS:我刚从我的旧项目中复制了这个,我不知道从哪里得到它.