Question

In my Java application I have a window which holds a JTextArea within a JScrollPane with scrollbars policies set to AS_NEEDED.

As I run my application I see that JTextArea this way: JTextArea with "weird" scrollbars

Why am I seeing the scrollbars with that cutaway knob (which doesn't reflect a "standard" representation like this)?

The Layout for the frame is GridBagLayout, and I'm on Mac OS X 10.8.2, should that matter.

Was it helpful?

Solution

This is based on the Look and Feel your app is using, and the limitations of Java's integration with the native OS layout components. The one in your screenshot looks like Nimbus.

Swing applications always custom-render the look and feel, and don't do a very good job of using the native OS widgets everywhere. The result is that you get weird looks that might be consistent the OS only some of the time, or only with certain layout components.

Welcome to developing cross-platform desktop apps in Java. :(

OTHER TIPS

To attempt to get the system look and feel when your application starts you can do this:

try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassname());
} catch (Exception e) {
    // Handle exception
}

This will set the look and feel to that of the system regardless of what you run it on.

And as mentioned, the default look and feel for your application appears to be Nimbus and not OSX's Aqua, which again can be fixed with he above snippet and you could (should you care to) offer a UI option to the user to change the look and feel of the application to whatever they chose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top