0 0 Votes

Java: Swing application should use operating system theme

Question by Guest | 13/05/2018 at 23:29

When I create a program using Java, the Widget Toolkit "Swing" is used for the GUI. The problem is that you can see that your app has this typical Java interface.

What can I do to make the program appear more native in style? Is there a way to just use the standard style or the default theme of the operating system?

ReplyPositiveNegative

Computer Expert

Show Profile | Message
Avatar
1Best Answer
1 Vote

To get the look and feel of your operating system in your Java program, you can use the following code right at the beginning of your main:

public static void main(String[] args) {

  String  style;
  style = javax.swing.UIManager.getSystemLookAndFeelClassName(); 

  try {
      UIManager.setLookAndFeel(style);
  } catch(Exception e) {     
      style = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
  } finally {
             
  }  

  // other code
} 

In the case of an exception, that is, when the loading of the standard theme goes awry, the nimbus design is used.
14/05/2018 at 13:33

ReplyPositive Negative
Reply

Related Topics

What is the best Operating System?
Open Voting | 5 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.