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 / February 2005

Tip: Looking for answers? Try searching our database.

JCheckBoxMenuItem cannot be checked

Thread view: 
Mr Smith - 17 Feb 2005 14:17 GMT
Hello,

i can't manage to check a JCheckBoxMenuItem. Here is the important code (mostly generated by eclipse 3.0.1):

   private javax.swing.JCheckBoxMenuItem getPointsCheckBoxMenuItem() {
       if (pointsCheckBoxMenuItem == null) {
           pointsCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
           pointsCheckBoxMenuItem.setText("Afficher les points");
           pointsCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() {
               public void actionPerformed(java.awt.event.ActionEvent e) {
                  //pointsCheckBoxMenuItem.getModel().isSelected()
                  System.err.println("pointsCheckBoxMenuItem.getState() = " + pointsCheckBoxMenuItem.getState());
                  System.err.println("pointsCheckBoxMenuItem.isSelected() = " + pointsCheckBoxMenuItem.isSelected());
                  if (pointsCheckBoxMenuItem.getModel().isSelected()) {
                      System.err.println("hide");
                      pointsCheckBoxMenuItem.setSelected(false);
                      getPointsJScrollPane().setVisible(false);
                      validate();
                      repaint();
                  } else {
                      System.err.println("show");
                      pointsCheckBoxMenuItem.setSelected(true);
                      getPointsJScrollPane().setVisible(true);
                      validate();
                      repaint();
                  }
               }
           });
           pointsCheckBoxMenuItem.setSelected(false);
       }
       return pointsCheckBoxMenuItem;
   }

the OUTPUT:

pointsCheckBoxMenuItem.getState() = true
pointsCheckBoxMenuItem.isSelected() = true
hide
pointsCheckBoxMenuItem.getState() = true
pointsCheckBoxMenuItem.isSelected() = true
hide

getState() is deprecated, it's just for testing

The checkbox is always detected as selected, while it is painted as it's not (in the menu, the item is NOT checked), and i can't select it!!

Any idea, plz?

TIA
Roland - 17 Feb 2005 14:47 GMT
> Hello,
>
[quoted text clipped - 45 lines]
>
> TIA
Your code resets the selected state immediately after it has been
selected: don't use
    pointsCheckBoxMenuItem.setSelected(false)
in the actionPerformed method (and neither with arg true). The GUI
component takes care of updating the selected state itself.
Signature

Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \

Mr Smith - 17 Feb 2005 15:28 GMT
Thx a lot!! It works!


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.