Getting java applications to look native on window

2020-06-03 04:18发布

Is it possible to use Java to create apps that look native on Windows? I don't care if the solution is portable or not, because I only plan to target windows users. I am using Scala if that matters.

Sorry for the lack of details, but I have never used Java before so I'm not even sure if this is possible.

8条回答
唯我独甜
2楼-- · 2020-06-03 04:47

Everyone else has posted Swing things, so I'm going to play Devil's advocate and mention SWT.

SWT is a widget toolkit produced by the Eclipse foundation. It is a thin wrapper over the system's native GUI... for Windows, OSX, and various flavors of *nix (Linux, AIX, BSDs?, etc...).

This is the opposite route that Sun's JFC/Swing took, which draws its own components.

查看更多
何必那么认真
3楼-- · 2020-06-03 04:52
try {
    // Set the Look and Feel of the application to the operating
    // system's look and feel.
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (ClassNotFoundException e) {
}
catch (InstantiationException e) {
}
catch (IllegalAccessException e) {
}
catch (UnsupportedLookAndFeelException e) {
}

That should set the Look and Feel to the system look and feel. You would do this before any of your GUI code. For example, in your main method.

If you want to learn more about Look and Feels, I would check out the Java Tutorial on them, as suggested by carwash.

查看更多
登录 后发表回答