java swing中改变改变Look and Feel外观的方法和步骤(转)_

本文介绍如何使用Java Swing更改应用程序的界面风格,包括通过UIManager.setLookAndFeel()方法设置不同的LookandFeel外观,如Metal、Motif及Windows风格,并通过SwingUtilities.updateComponentTreeUI()方法更新界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 利用UIManager.setLookAndFeel()方法(这个方法需要传入正确的Look and Feel名称,如下)设置新的Look and Feel外观。
    Metal风格——"javax.swing.plaf.metal.MetalLookAndFeel"
    Motif风格——"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
    Windows风格——"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
2. 用SwingUtilities.updateComponentTreeUI()方法改变外观。

示例代码:
try {
    UIManager.setLookAndFeel(lnfName);
    SwingUtilities.updateComponentTreeUI(frame);
}
catch (UnsupportedLookAndFeelException ex1) {
    System.err.println("Unsupported LookAndFeel: " + lnfName);
}
catch (ClassNotFoundException ex2) {
    System.err.println("LookAndFeel class not found: " + lnfName);
}
catch (InstantiationException ex3) {
    System.err.println("Could not load LookAndFeel: " + lnfName);
}
catch (IllegalAccessException ex4) {
    System.err.println("Cannot use LookAndFeel: " + lnfName);
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值