aspose file tools*
The moose likes Mac OS and the fly likes Mac help - I thought Java was platform independent? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Mac help - I thought Java was platform independent?" Watch "Mac help - I thought Java was platform independent?" New topic
Author

Mac help - I thought Java was platform independent?

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10520
    
    9

Here's the problem, on Windows, surprisingly, everything works well; but on a Mac there is a problem with the sliders.

Since this problem looks to be specific only to Mac, I will move this thread over to the Mac forum.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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:



[Jess in Action][AskingGoodQuestions]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
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.


Ping & DNS - my free Android networking tools app
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42601
    
  65
Ah, sorry - after a more thorough second reading of the post I see where I misunderstood the problem.

There are some ways to customize a slider's appearance on Aqua, but not apparently the background color: http://nadeausoftware.com/articles/2009/04/mac_java_tip_how_customize_aqua_sliders. Maybe the "track color" hint works if you do custom painting.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Is there a way to turn Aqua off for this application?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Ernest Friedman-Hill wrote:
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Yes, you can set the look and feel from code using the UIManager class. You just want to do something like this at the beginning of the app:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Yes, Yoda, I am learning.

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.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Paul!

Say more about the phrase:

dog's breakfast


Never heard it before - sounds fun...

Bert

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
wood burning stoves
 
subject: Mac help - I thought Java was platform independent?