• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mac help - I thought Java was platform independent?

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to turn Aqua off for this application?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul!

Say more about the phrase:

dog's breakfast



Never heard it before - sounds fun...

Bert
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic