Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to switch the Metal look and feel in Swing

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to switch the Metal look and feel in Swing". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to switch the Metal look and feel in Swing".

By default, the Swing program uses Metal look and feel, which can be changed in two ways.

The first way is to have a file swing.properties in jre / lib under the subdirectory of the Java installation. In this file, set the property Swing.defaultlaf to the desired look and feel class name. For example:

Swing.defaultlaf = com.sun.java.swing.plaf.motif.MotifLookAndFeel

Ps: in the first way, I couldn't find the swing.properties. I don't know what everyone's doing.

Notice that the Metal look and feel is in the Javax.swing package. Other look and feel packages are located in the com.sun.java package and are not provided in every Java implementation. Now, for copyright reasons, the look and feel packages for Windows and Mac are only released with the Windows and Mac versions of the java runtime.

Tip: here is a helpful suggestion for testing. Since lines starting with the # character in the properties file are ignored, you can provide several impressions in the swing.properties file and switch choices by adding or deleting the # character:

◆ swing.defaultlaf = javax.swing.plaf.metal.MetalLookAndFeel

◆ swing.defaultlaf = com.sun.java.swing.plaf.motif.MotifLookAndFeel

◆ swing.defaultlaf = com.sun.java.swing.plaf.windows.WindowsLookAndFeel

The program must be restarted when opening the look and feel in this way. The Swing program reads the swing.properties file only once when it starts.

The second way is to change the perception dynamically. This requires calling the static UIManager.setLookAndFeel method, providing the desired look and feel class name, and then calling the static method SwingUtilities.updateComponentTreeUI to refresh the entire set of components. Here you need to provide a component to this method and find all the other components accordingly. An exception is thrown when the UIManager.setLookAndFeel method does not find the desired look and feel or when an error occurs during loading.

Here is an example of how to switch the look and feel in a program. This is something to pay attention to in this program. In the actionPerformed method of the internal action listener class, you need to pass an external this reference of the PalfPanel class to the updateComponentTreeUI method.

The above is all the contents of the article "how to switch the Metal look and feel in Swing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report