Results 1 to 3 of 3
  1. #1
    cyentw is offline Member
    Join Date
    Jan 2013
    Posts
    14
    Rep Power
    0

    Default Help with JCheckBox

    So, what I'm trying to do here is have the system print "test" when a JCheckBox from my GUI is checked.

    Code:
    Java Code:
    		foodcheck.addActionListener(this); 
    //I added an action listener to the checkbox
    later down:
    Java Code:
    		if (foodcheck.isSelected()) {
    		       System.out.print("test");
    		   }
    foodcheck is the JCheckBox.

    Help please!

  2. #2
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    317
    Rep Power
    2

    Default Re: Help with JCheckBox

    Try doing the method
    Java Code:
    public void actionPerformed(ActionEvent e) {
    System.out.print("test");
    }
    Good Luck!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with JCheckBox

    Quote Originally Posted by MW130 View Post
    Try doing the method
    Java Code:
    public void actionPerformed(ActionEvent e) {
    System.out.print("test");
    }
    Good Luck!
    No, this will print any time the check box is checked, regardless if it has been unselected or selected. The best solution is to read the check box tutorial and add an ItemListener as demonstrated in the tutorial.

Similar Threads

  1. jcheckbox and jtable
    By seredi in forum New To Java
    Replies: 2
    Last Post: 05-05-2012, 08:08 AM
  2. JCheckBox help
    By lawrenceejgray in forum AWT / Swing
    Replies: 3
    Last Post: 11-12-2011, 05:38 PM
  3. JCheckBox
    By bczm8703 in forum JDBC
    Replies: 1
    Last Post: 10-23-2011, 06:30 PM
  4. Jcheckbox problem
    By xyknight in forum New To Java
    Replies: 10
    Last Post: 04-09-2011, 05:40 PM
  5. How can I add JCheckBox to each row?
    By batya in forum AWT / Swing
    Replies: 1
    Last Post: 11-04-2009, 10:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •