Results 1 to 6 of 6
  1. #1
    msixty is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Question Checkbox to list

    I need a code which will add text to a list when a checbox is checked.

    This is a code I tried on Netbeans, whic didnt work.;)

    Java Code:
    private void check1ActionPerformed(java.awt.event.ActionEvent evt){
         if(HDD.equals("HDD")){
               list1.add("Sata");
         }

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Small suggestion.Just add trim() to HDD and try

    private void check1ActionPerformed(java.awt.event.ActionEvent evt){
    if(HDD.trim()equals("HDD")){
    list1.add("Sata");
    }
    Ramya:cool:

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

    Default

    You may want to post more relevant code here to give us a better idea of why your attempt doesn't work.

  4. #4
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    check1ActionPerformed ?
    how to call this method from click action?

  5. #5
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    For a standard way to respond to a checkbox being clicked, see this example of JCheckBox. To get your code to work, you need to make sure that:

    - this funny check1ActionPerformed() method actually is being called by the actionPerformed() method of a listener that is actually registered with the JCheckBox
    - that your comparison HDD.equals("HDD") turns out to be true (remember, without being telepathic, we don't know what this line is trying to do and can't assess whether or not it's doing it properly)

  6. #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    also use .equalsIgnoreCase() when comparing strings, unless of course the case really matters
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. [SOLVED] Checkbox new to Java
    By s34nn4 in forum Java Applets
    Replies: 11
    Last Post: 04-12-2009, 05:21 AM
  2. CheckBox Jlist items
    By dropez in forum AWT / Swing
    Replies: 1
    Last Post: 03-26-2009, 07:39 PM
  3. Displaying a price with a checkbox
    By F4iChick02 in forum New To Java
    Replies: 4
    Last Post: 12-09-2008, 05:13 AM
  4. How to use ItemListener for CheckBox class
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 04-23-2008, 08:18 PM
  5. checkbox
    By Alan in forum AWT / Swing
    Replies: 3
    Last Post: 05-18-2007, 10:10 AM

Posting Permissions

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