I am new to Java programming and want to whether it is possible to get the windows native look in Java GUI applications. Obviously Swing won't work.
Asked
Active
Viewed 7.1k times
3 Answers
89
Use the following:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Read UIManager and How to Set the Look and Feel for more information.

tenorsax
- 21,123
- 9
- 60
- 107
-
if you use this you have to do the update as you can see in Kumar answer below: `SwingUtilities.updateComponentTreeUI(frmae);` `updateComponentTreeUI(frame);` – SüniÚr Nov 10 '14 at 08:44
-
2@Csanesz if you change the L&F after the application start up when the UI is already visible then `updateComponentTreeUI` is required, otherwise it is not needed. The mentioned tutorial discusses various options. – tenorsax Nov 11 '14 at 20:12
-
Don't forget to surround it with try/catch (checked exceptions) – Devid Feb 23 '23 at 14:59
16
Try this....
The syntax is:
UIManager.setLookAndFeel(PLAF); (Pluggable Look and Feel)
So, you must include the below 3 lines.
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(frame);
updateComponentTreeUI(frame);
SwingUtilities.updateComponentTreeUI(frame) is used for refreshing the frame after the change.

Kumar Vivek Mitra
- 33,294
- 6
- 48
- 75
-
3a) not recommended to hard-code class names b) no need for the third of the three lines (it's already handled in the second :-) – kleopatra Jul 11 '12 at 08:01
-
9Only the first line is necessary, if you run it before realizing any GUI components. – Jacob Raihle Jul 11 '12 at 08:06
-4
try this code:
javax.swing.UIManager.setLookAndFeel("Windows")

Madhawa Priyashantha
- 9,633
- 7
- 33
- 60

Tan Hao
- 41
- 1
-
19-1 wrong - you would at least need the fully qualified classname of the LAF – kleopatra Jul 11 '12 at 07:58
-
@RonE dooh, nearly fainted and quickly tried (which you might have done as well ;-) It's throwing `java.lang.ClassNotFoundException: Windows` just as documented, so curious: why do you think that? – kleopatra Jan 19 '14 at 12:23
-
@kleopatra My mistake, I'm just so used to a helper method that makes use of parameter `lookAndFeelString` to select the L&F. `for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if (lookAndFeelString.equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName());}}` I'll remove my other comment to not be misleading. – Ron Jan 21 '14 at 09:23