This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMenuBar problem in MAC

 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an issue with the JMenuBar in MAC. My application is developed by swing and the issue is with the swing JMenuBar. There are two levels(submenus) in the JemnuBar. Once I focus on the first menu link it slides and it displays the second menu(this is the normal behavior). But when I CLICK on the first menu it result in disappearing the menu without sliding to the second menu. But this work fine in windows. Is there any reason for this?

Thank You
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with Macs, but does this behaviour differ from other applications? If not, then it may be part of the Mac look&feel.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
does this behaviour differ from other applications?


Yes this behavior is different from other applications. Applications like safari, mac office does not have that. Only occurred when we are programming in swing. And also I am using system default mac look and feel. Other part of the application which is associated with mac look and feel still works fine. Is there any workaround I can do for this issue or is that some sort of a bad programming practice I have applied?

Thank you.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the only thing that I have done to that specific menu,

JMenu intoTab = new JMenu("Test");
intoTab.setActionCommand("test");
intoTab.setMnemonic(KeyEvent.VK_I);
intoTab.setEnabled(true);
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also note that I have added System.setProperty("apple.laf.useScreenMenuBar", "true") in the coding, so that all the menu items will be in the Mac menu bar. Once I make this false it appear as a normal JFrame window with the menu bar and it does not produce this issue.
The reason for this behavior is moving the menubar from the frame to mac os menu bar position.
I tried to solve this issue by making it heavyweight using JPopupMenu.setDefaultLightWeightPopupEnabled(false. But also it did not work.
Any suggestions?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you app. runs on MAC it will pick up the MAC LAF. No need for you to explicitly set anything else.
Note. This MUST be called before your create your UI. Typically, I make this the first line in my main method.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:
This MUST be called before your create your UI.

Not true. If you change the look&feel later, it will not be updated for existing components automatically. By calling SwingUtilities.updateComponentTreeUI you can still force the update.
[ August 19, 2008: Message edited by: Rob Prime ]
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True.
However it would be easier to do it once at the start. I cannot think of any real life scenario where anyone would want to change the LAF at runtime as it would be bad usability.
 
ashok kandaswamy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dilshan Edirisuriya:
Also note that I have added System.setProperty("apple.laf.useScreenMenuBar", "true") in the coding, so that all the menu items will be in the Mac menu bar. Once I make this false it appear as a normal JFrame window with the menu bar and it does not produce this issue.
The reason for this behavior is moving the menubar from the frame to mac os menu bar position.
I tried to solve this issue by making it heavyweight using JPopupMenu.setDefaultLightWeightPopupEnabled(false. But also it did not work.
Any suggestions?



HI Edirisuriya,

In mac normally we don't want to set any look and feel.because mac takes the menubar for it's own.so you don't set any look and feel in the code for mac implementation.just gave it as without any look and feel code...then i will hope now it will works fine.because the same issue i had faced in mac with swing application....

--ashok---
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ashok", please check your private messages for an important administrative matter.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply.

I have not done any system look and feel coding here. Only used the System.setProperty("apple.laf.useScreenMenuBar", "true") to set the menu bar in mac screen menu bar. This problem occurs only in mac screen menu bar. It does not reproduce when I am using the menubar within the JFrame.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ashok:
In mac normally we don't want to set any look and feel.because mac takes the menubar for it's own.


I have my doubts about it. Without invoking UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); you will end up with the default LAF.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies,

Check this link as well

http://forums.macosxhints.com/showthread.php?p=489302#post489302

This is a reply I got in the mac forum. Is this actually bug? Is there anyone who has face this situation before?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try it out with
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Maneesh but still it did not work. Thanks. I think something wrong when we are moving the menubar from the frame in to the mac os menu bar.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic