I have a small application, the purpose is to place six sliders and a test panel in a window. Three of the sliders control the background color, the other three control the foreground color, and a section between them displays the value of the sliders and a sample text. The purpose is to help pick color combinations which are readable, both for Java programming and web design.
Here's the problem, on Windows, surprisingly, everything works well; but on a Mac there is a problem with the sliders. Part of the code is to change the background color of each slider so that I can see the level of each color. This is minor, and doesn't affect the purpose of the application, except for not knowing which slider controls which color.
Java is portable, but it's not platform-independent in the sense that everything is always exactly the same on every machine. In particular, Swing has the notion of a "pluggable look and feel," a sort of skinning system so that the GUI for an application can look like the host platform's native GUI. The quick explanation for what's happening is that the Mac look and feel, which you'll see by default, doesn't support background colors for many widgets, because the Mac doesn't include this idea as part of its look and feel guidelines. If you tell Java not to use the Mac look and feel, but rather to use the "Metal" look and feel (which is a platform-agnostic look and feel which doesn't look right on any OS), then you'll see your program working as expected on the Mac:
Not even using the Metal L&F will result in a pixel-by-pixel identical GUI, since the Mac uses different default fonts and font sizes. At least part of the problem is that the code sets a fixed size for the window. You're much better off not doing that, and instead calling pack() after all the GUI creation is done. Then you can let Swing figure out what the best size is on any given OS.
posted 9 years ago
Ulf Dittmer wrote:Not even using the Metal L&F will result in a pixel-by-pixel identical GUI, since the Mac uses different default fonts and font sizes. At least part of the problem is that the code sets a fixed size for the window. You're much better off not doing that, and instead calling pack() after all the GUI creation is done. Then you can let Swing figure out what the best size is on any given OS.
I don't understand how that would effect the background colors on the sliders...that is the problem I am having.
posted 9 years ago
Ah, sorry - after a more thorough second reading of the post I see where I misunderstood the problem.
Mike Lipay wrote:Is there a way to turn Aqua off for this application?
Did you see my post above? That's exactly what it does.
I'm sorry, yes I did see that. What I meant is, s there a way to turn Aqua off from within the application, rather than trying to remember that this application needs the option every time it is compiled.
There's two possible meanings for "platform independent". One is that the applications look the same no matter which platform they run on. The other is that the applications behave in the standard way for the platform they run on.
So in the second case, a Java application run on a Mac looks like all other applications which run on a Mac, but not necessarily like the same application run on Windows. In the first case a Java application run on a Mac looks like the same application run on Windows, but not necessarily like other applications run on a Mac.
And as you can see, when different bits and pieces happen to implement different meanings of "platform independent" you get a dog's breakfast where your application on Mac doesn't quite look like a Mac application and it doesn't quite look like the same application on Windows either.
What I have decided on is to keep the platform appearance, but to add a small box next to the sliders that will change color. That way I can keep the Mac and Windows look, while still giving the feedback I require.