public class UIResourceTest extends javax.swing.JFrame
{
/** Creates new form UIResourceTest */
public UIResourceTest() {
initComponents();
}
private void initComponents() {
//GEN-BEGIN:initComponents
jTextArea1 = new javax.swing.JTextArea("Test",10,10);
//jTextArea1.set
jScrollPane1 = new javax.swing.JScrollPane(jTextArea1);
button = new javax.swing.JButton("TestButton");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
getContentPane().add(button, java.awt.BorderLayout.SOUTH);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(200, 150));
setLocation((screenSize.width-150)/2,(screenSize.height-100)/2);
}
//GEN-END:initComponents
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
//GEN-FIRST:event_exitForm
System.exit(0);
}
//GEN-LAST:event_exitForm
/*** @param args the command line arguments*/
public static void main(String args[]) {
try{
javax.swing.UIDefaults ui = javax.swing.UIManager.getDefaults();
java.util.Enumeration enum = ui.keys();
java.awt.Font font = new java.awt.Font("宋体", java.awt.Font.BOLD, 20);
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
System.out.println(key); if (key.indexOf(".font") > 0) {
javax.swing.UIManager.put(key, font);
}
} javax.swing.UIManager.put("ScrollBar.thumb", new javax.swing.plaf.ColorUIResource(33,129,176));
javax.swing.UIManager.put("Button.foreground", new javax.swing.plaf.ColorUIResource(255,0,0));
}catch(Exception e){
e.printStackTrace();
}
UIResourceTest test = new UIResourceTest();
test.show();
}
// Variables declaration - do not modify
//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JButton button;
// End of variables declaration
//GEN-END:variables
}
{
/** Creates new form UIResourceTest */
public UIResourceTest() {
initComponents();
}
private void initComponents() {
//GEN-BEGIN:initComponents
jTextArea1 = new javax.swing.JTextArea("Test",10,10);
//jTextArea1.set
jScrollPane1 = new javax.swing.JScrollPane(jTextArea1);
button = new javax.swing.JButton("TestButton");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
getContentPane().add(button, java.awt.BorderLayout.SOUTH);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(new java.awt.Dimension(200, 150));
setLocation((screenSize.width-150)/2,(screenSize.height-100)/2);
}
//GEN-END:initComponents
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
//GEN-FIRST:event_exitForm
System.exit(0);
}
//GEN-LAST:event_exitForm
/*** @param args the command line arguments*/
public static void main(String args[]) {
try{
javax.swing.UIDefaults ui = javax.swing.UIManager.getDefaults();
java.util.Enumeration enum = ui.keys();
java.awt.Font font = new java.awt.Font("宋体", java.awt.Font.BOLD, 20);
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
System.out.println(key); if (key.indexOf(".font") > 0) {
javax.swing.UIManager.put(key, font);
}
} javax.swing.UIManager.put("ScrollBar.thumb", new javax.swing.plaf.ColorUIResource(33,129,176));
javax.swing.UIManager.put("Button.foreground", new javax.swing.plaf.ColorUIResource(255,0,0));
}catch(Exception e){
e.printStackTrace();
}
UIResourceTest test = new UIResourceTest();
test.show();
}
// Variables declaration - do not modify
//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JButton button;
// End of variables declaration
//GEN-END:variables
}
javax.swing.UIManager.put(key, font);
}你可以把系统中所有字体任意替换成你想要的字体。
关于字体呢~有2中
一种是本地化与国际化,这个一般用与大型开发的语言设置问题,普通用户是不会用到的~
还有就是字体问题,这个和好解决的,在jdk中有相映的方法,就是component类提供获得 和改变当前字体信息的方法,具体方法就是楼上的