• 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

JMenuBar problem in MAC

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
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

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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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---
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
Did you try it out with
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic