Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

How to prevent automatic change state of a JCheckBoxMenuItem

Thread view: 
Mr Smith - 09 Mar 2005 15:05 GMT
Hello,

i have a JMenu, with JCheckBoxMenuItem in it.

When the user clicks on a JCheckBoxMenuItem, i open a JDialog, and if the user select "Cancel", i want to undo the checking of the menu item.

If it's possible, i would like to prevent the changes of the menu item state.

If it's not possible, i will subclass JCheckBoxMenuItem, and add  saveState() / restoreState().

So is it possible to prevent the automatic change?

TIA
Andrey Kuznetsov - 09 Mar 2005 20:47 GMT
> When the user clicks on a JCheckBoxMenuItem, i open a JDialog, and if the
> user select "Cancel", i want to undo the checking of the menu item.

since JCheckBoxMenuItem is subclass of AbstractButton you can use
JCheckBoxMenuItem#setSelected(false);

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Mr Smith - 10 Mar 2005 09:18 GMT
> > When the user clicks on a JCheckBoxMenuItem, i open a JDialog, and if the
> > user select "Cancel", i want to undo the checking of the menu item.
> >
> since JCheckBoxMenuItem is subclass of AbstractButton you can use
> JCheckBoxMenuItem#setSelected(false);

No because if the item was already the one selected, i must not unselect it.

i will add a saveSelectedState()/restoreSelectedState()
Mr Smith - 10 Mar 2005 16:22 GMT
> i will add a saveSelectedState()/restoreSelectedState()

for those who are interested, i didn't manage to make it work, i had to do a special JMenu which only allow 1 JMenuItem selected at a time (i don't select through "item.setSelected()" anymore but with "menu.SetSelectedItem(item)".
Andrey Kuznetsov - 10 Mar 2005 17:32 GMT
>> i will add a saveSelectedState()/restoreSelectedState()
>
> for those who are interested, i didn't manage to make it work, i had to do
> a special JMenu which only allow 1 JMenuItem selected at a time (i don't
> select through "item.setSelected()" anymore but with
> "menu.SetSelectedItem(item)".

why don't you post your code, may be some one can help you?

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.