Programming and general geekiness.

Posts tagged ‘java swing’

Get Java Swing to use the Operating System style

Java Swing is an incredibly easy way of designing a user interface however there’s a major problem with it: the default style is disgusting. The default style that shows up is really horrible because it is designed to be a mix of the designs of Windows, Mac and Linux so that a button is recognizable as a button but not as nice as the default style. Thankfully there is a really easy way to change an app from looking like the one on the right to the default OS style on the left. It is worth noting (as demonstrated by the position of the Next button) that this doesn’t always work brilliantly but that it does look better.

All you have to do is make sure you have imported javax.swing.UIManager and then add the following code before you create the interface:

catch (Exception e) { }

This will fetch the OS’ default style allowing you to easily use it in your application. On Mac this application’s menu should display at the top rather than in the window itself, thus allowing your application to look nice on all platforms.