aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JMenuBar problem in MAC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenuBar problem in MAC" Watch "JMenuBar problem in MAC" New topic
Author

JMenuBar problem in MAC

Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
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


Dilshan Edirisuriya SCJP1.4, SCWCD1.4, SCBCD 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
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

Joined: Apr 22, 2006
Posts: 299
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

Joined: Apr 22, 2006
Posts: 299
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

Joined: Jul 26, 2007
Posts: 9990
    
    7


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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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

Joined: Jul 26, 2007
Posts: 9990
    
    7

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

Joined: Aug 19, 2008
Posts: 16
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---


Sk.Ashokkumar.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

"ashok", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

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

Joined: Apr 22, 2006
Posts: 299
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

Did you try it out with
Dilshan Edirisuriya
Ranch Hand

Joined: Apr 22, 2006
Posts: 299
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMenuBar problem in MAC
 
Similar Threads
Swing: JMenu shows close+minimize on mac
dynamic menubar
Menu question?
addActionListener problem
JMenu Update