i have a question about JMenuBar in Java on Os X
i'm programming a little application just for fun
Explaination about the program and my problem :
I have a login part and a menu part
when i'm not logged in the menu is like "File - New - Profile - ?"
this is in my menuBar
but everything in NEW and in PROFILE are disabled ( because you can only use this option when you'r logged)
my code is :
as you can see I disable the items that i don't need before login
but after ... i call this method back and .... in theory this items are ENABLE but ...
it doesn't work
Not sure that this is a Mac issue - probably a general Swing issue....
How are you calling these methods to set up the menu bar? Is it on the event thread? If not, that's why the visual state of the JMenuBar isn't updating correctly.
-Nate
--------------------------------
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Hmmmm.... still not sure if it's on the event thread.
To call something on the event thread it either gets called from a listener, or through a Runnable that gets invoked through SwingUtilities.invokeLater()/invokeAndWait() (or uses SwingWorker,etc. which uses invokeLater/invokeAndWait).
Instead of embedding all this code directly in a JMenuBar subclass, it would probably be better to write this code as a listener for whatever component the user uses to login - or at least this code should get called from that listener.
-Nate
--------------------------------
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
if the component (frame) is already visible, any time you add or remove components,
you need to validate/revalidate the container and most times also call repaint.
I tried like you said ... but not working
actually
in my Gui class i have this
as you can see i call my setJMenuBar ...
and my setMenuBar() method return a JMenuBar
so when i call it from my class Login
( from the eventListener )
i don't use the return ... ( i was thinking that revalidate(); and repaint(); will work ) but no ...
and i really don't get it.
when i open my programm i have a menu ( like i said here above ) by calling a method
some parts of this menu are hidden this is my class :
when people wanted to login they enter the password and login and click on validate
my class Login is called and the event is checked by
as we can see i check my loggin here and then ( it comes back above to the event to look to the Method set login )
as we can see above ( in my class ) i checke that i'm logged and ( i have a print in shell that i'm logged ) but
the hidden parts of the menu are appearing
This message was edited 2 times. Last update was at by xavier be
all you need is to disable them, then enable them when logged in.
one way might be to put a reference to each menuitem (to be dis/enabled)
in an array, then create a method
call this method after you create the menuBar (with false for state)
call it again after login (with true for state)
Very sorry for not answering during all this time ...
and thanks for your post
i saw that you run everything in a thread this actually a nice solution ( and workig solution )
i saw also your array wich is a very good idea i'll try it