javax.swing.UIManager

本文详细介绍了Java Swing中UIManager类和LookAndFeel类的作用,列举了多种预设的界面风格,如Metal、Windows、Motif等,并提供了代码示例,展示了如何在Swing应用中切换不同的界面风格。

javax.swing.UIManager类和LookAndFeel类

javax.swing.UIManager类

javax.swing.UIManager类是Swing界面管理核心,管理Swing应用程序样式。

LookAndFeel类

与javax.swing.UIManager类密切相关的就是LookAndFeel抽象类。它除了提供static方法,还定义抽象的个性化设置方法由子类实现。

Sun提供了三个LookAndFeel子类:

javax.swing.plaf.metal.MetalLookAndFeel(Metal样式)	    
com.sun.java.swing.plaf.motif.MotifLookAndFeel(Motif样式)
com.sun.java.swing.plaf.windows.WindowsLookAndFeel(Windows样式)。

Java中的几种LookandFeel(此部分代码在main方法打开GUI界面之前实现)
1、Metal风格(默认)
String lookAndFeel =“javax.swing.plaf.metal.MetalLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);

2、Windows风格
String lookAndFeel =“com.sun.java.swing.plaf.windows.WindowsLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);

3、Windows Classic风格
String lookAndFeel =“com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);

4、Motif风格
String lookAndFeel =“com.sun.java.swing.plaf.motif.MotifLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);

5、Mac风格 (需要在相关的操作系统上方可实现)
String lookAndFeel =“com.sun.java.swing.plaf.mac.MacLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);

6、GTK风格 (需要在相关的操作系统上方可实现)
String lookAndFeel =“com.sun.java.swing.plaf.gtk.GTKLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
7、可跨平台的默认风格
String lookAndFeel =UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);

8、当前系统的风格
String lookAndFeel =UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
————————————————
原文链接

$ "/opt/oracle/database/runInstaller" -silent -responseFile /"/opt/oracle/database/response/db_install.rsp" -ignorePrereq 正在启动 Oracle Universal Installer... 检查临时空间: 必须大于 120 MB。 实际为 37572 MB 通过 检查交换空间: 必须大于 150 MB。 实际为 3865 MB 通过 准备从以下地址启动 Oracle Universal Installer /tmp/OraInstall2025-08-01_01-12-05PM. 请稍候...$ MoTTY X11 proxy: No authorisation provided Exception in thread "main" java.lang.NoClassDefFoundError at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at java.awt.Toolkit$2.run(Toolkit.java:821) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:804) at javax.swing.UIManager.initialize(UIManager.java:1262) at javax.swing.UIManager.maybeInitialize(UIManager.java:1245) at javax.swing.UIManager.getUI(UIManager.java:851) at javax.swing.JPanel.updateUI(JPanel.java:104) at javax.swing.JPanel.<init>(JPanel.java:64) at javax.swing.JPanel.<init>(JPanel.java:87) at javax.swing.JPanel.<init>(JPanel.java:95) at oracle.sysman.oii.oiif.oiifo.OiifoOCMUI.<init>(OiifoOCMUI.java:125) at oracle.sysman.oii.oiif.oiifo.OiifoOCMInterfaceManager.<init>(OiifoOCMInterfaceManager.java:79) at oracle.sysman.oii.oiif.oiifo.OiifoOCMInterfaceManager.getInstance(OiifoOCMInterfaceManager.java:124) at oracle.install.ivw.db.driver.DBInstaller.run(DBInstaller.java:123) at oracle.install.commons.util.Application.startup(Application.java:869) at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:164) at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:181) at oracle.install.commons.base.driver.common.Installer.startup(Installer.java:265) at oracle.install.ivw.db.driver.DBInstaller.startup(DBInstaller.java:114) at oracle.install.ivw.db.driver.DBInstaller.main(DBInstaller.java:132)
08-02
[root@yfw xvfb-extract]# java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jivesoftware.launcher.Startup.start(Startup.java:75) at org.jivesoftware.launcher.Startup.main(Startup.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:84) at com.install4j.runtime.launcher.UnixLauncher.start(UnixLauncher.java:69) at install4j.org.jivesoftware.launcher.Startup.main(Unknown Source) Caused by: java.awt.AWTError: Can't connect to X11 window server using ':99' as the value of the DISPLAY variable. at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method) at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65) at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115) at java.security.AccessController.doPrivileged(Native Method) at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82) at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:131) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at java.awt.Toolkit$2.run(Toolkit.java:860) at java.awt.Toolkit$2.run(Toolkit.java:855) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854) at sun.swing.SwingUtilities2.getSystemMnemonicKeyMask(SwingUtilities2.java:2032) at javax.swing.plaf.basic.BasicLookAndFeel.initComponentDefaults(BasicLookAndFeel.java:1158) at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:431) at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:148) at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1577) at javax.swing.UIManager.setLookAndFeel(UIManager.java:539) at javax.swing.UIManager.setLookAndFeel(UIManager.java:579) at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1349) at javax.swing.UIManager.initialize(UIManager.java:1459) at javax.swing.UIManager.maybeInitialize(UIManager.java:1426) at javax.swing.UIManager.getInstalledLookAndFeels(UIManager.java:419) at javax.swing.UIManager.installLookAndFeel(UIManager.java:462) at javax.swing.UIManager.installLookAndFeel(UIManager.java:481) at org.jivesoftware.spark.ui.themes.LookAndFeelManager.<clinit>(LookAndFeelManager.java:40) at org.jivesoftware.Spark.startup(Spark.java:163) ... 13 more [root@yfw xvfb-extract]# # 查看是否有新的 Java 进程(属于 Spark) [root@yfw xvfb-extract]# ps aux | grep java | grep openfire openfire 1328 0.2 8.5 3934888 327272 ? Sl Oct16 41:51 /usr/lib/jvm/java-11/bin/java -server -Djdk.tls.ephemeralDHKeySize=matched -Djsse.SSLEngine.acceptLargeFragments=true -Dlog4j.configurationFile=/opt/openfire/bin/../lib/log4j2.xml -Dlog4j2.formatMsgNoLookups=true -Dlog4j.skipJansi=false -DopenfireHome=/opt/openfire/bin/../ -Dopenfire.lib.dir=/opt/openfire/lib -classpath /opt/openfire/.install4j/i4jruntime.jar:/opt/openfire/.install4j/launchere44106de.jar:/opt/openfire/lib/* install4j.org.jivesoftware.openfire.starter.ServerStarter start openfire 4101 0.1 5.0 3746016 194592 ? Sl Oct16 28:13 /usr/lib/jvm/java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64/bin/java -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Dconfig.file=/opt/openfire/bin/../plugins/pade/classes/jvb/application.conf -Dnet.java.sip.communicator.SC_HOME_DIR_LOCATION=/opt/openfire/bin/../plugins/pade/classes/jvb -Dnet.java.sip.communicator.SC_HOME_DIR_NAME=config -Djava.util.logging.config.file=./logging.properties -Djdk.tls.ephemeralDHKeySize=2048 -cp ./jitsi-videobridge-2.1-SNAPSHOT.jar:./jitsi-videobridge-2.1-SNAPSHOT-jar-with-dependencies.jar org.jitsi.videobridge.MainKt --apis=rest openfire 4124 0.0 2.8 3737208 107320 ? Sl Oct16 14:17 /usr/lib/jvm/java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64/bin/java -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Dconfig.file=/opt/openfire/bin/../plugins/pade/classes/jicofo/application.conf -Dnet.java.sip.communicator.SC_HOME_DIR_LOCATION=/opt/openfire/bin/../plugins/pade/classes/jicofo -Dnet.java.sip.communicator.SC_HOME_DIR_NAME=config -Djava.util.logging.config.file=./logging.properties -Djdk.tls.ephemeralDHKeySize=2048 -cp ./jicofo-1.1-SNAPSHOT.jar:./jicofo-1.1-SNAPSHOT-jar-with-dependencies.jar org.jitsi.jicofo.Main --host=localhost --port=5275 --domain=localhost --secret=ElaQPVPKh05Zy4pb3Rgrvmm5XFoXVadRneWHyRqr --user_domain=localhost --user_name=focus --user_password=yra84zlHMIbfpL8CQpJDYDz5ODmtQXPpoRVds1WN [root@yfw xvfb-extract]#
最新发布
10-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值