开发者

Native LAF for all platforms through java

开发者 https://www.devze.com 2023-03-22 08:23 出处:网络
I am currently working with swing applications.For a developer ,it is most important that the user must be comfortable with the GUI.I want to develop an application which can have the native (Platform

I am currently working with swing applications.For a developer ,it is most important that the user must be comfortable with the GUI.I want to develop an application which can have the native (Platform's default) look and feel for all platforms that are used on a computer(I mean to say my application is not intended for mobile devices).The code I am using for the same is

        UIManager.setLookAndFee开发者_高级运维l(
            UIManager.getSystemLookAndFeelClassName()); 

Is there any simpler or more effective method for achieving the same thing?


Is there any simpler or more effective method for achieving the same thing?

No, there isn't


Yes, you can make it "simpler":

public static void useSystemLaF()
{
    try {
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {}
}

And then:

useSystemLaF();

Conclusion: This isn't simpler. There is no way to do this easier. You can put the method in a utility class, which make your code look better, if it is that what you want.


Simpler? Sure, use SWT, you won't need those two lines of code to make it look native ^_^

If you want to use Swing, setting native look and feel might not be enough. This is one of those "Run once, test everywhere" things. It doesn't get simpler, only more complicated and hack-ish.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号