Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Issues with ListSelectionEvent


    F00
     Share

    Recommended Posts

    I attempted to make a simple GUI for my script, and the primary components are a combobox, a jlist, and a button. I'm having an issue where when I add a ListSelectionListener and attempt to use .equals() or .contains()  on Jlist.getSelectedValue() it freezes the list and stops it from updating when I select a new combobox item.

    the method looks like this :

     

    private void locationListActionPerformed(ListSelectionEvent e)
    {
       if (!e.getValueIsAdjusting()) {
          String location = locationList.getSelectedValue();
          if (location.equals("Lumbridge Swamp") || location.equal("Lumbridge River")) {
             bankCheckBox.setSelected( false );
             bankCheckBox.setEnabled( false );
          } else {
             bankCheckBox.setEnabled(true);
          }
       }
    
    }
    

    however if I use location == "Lumbridge Swamp" it works just fine.

    Could someone please explain why this is happening. Thank you.

     

    Link to comment
    Share on other sites

    10 hours ago, F00 said:

    I attempted to make a simple GUI for my script, and the primary components are a combobox, a jlist, and a button. I'm having an issue where when I add a ListSelectionListener and attempt to use .equals() or .contains()  on Jlist.getSelectedValue() it freezes the list and stops it from updating when I select a new combobox item.

    the method looks like this :

     

    private void locationListActionPerformed(ListSelectionEvent e)
    {
       if (!e.getValueIsAdjusting()) {
          String location = locationList.getSelectedValue();
          if (location.equals("Lumbridge Swamp") || location.equal("Lumbridge River")) {
             bankCheckBox.setSelected( false );
             bankCheckBox.setEnabled( false );
          } else {
             bankCheckBox.setEnabled(true);
          }
       }
    
    }
    

    however if I use location == "Lumbridge Swamp" it works just fine.

    Could someone please explain why this is happening. Thank you.

     

    getSelectedValue returns an Object, you must either cast it to String or add a .toString();

    also its .equals("...") not .equal("..)

    Link to comment
    Share on other sites

    13 hours ago, Defiled said:

    getSelectedValue returns an Object, you must either cast it to String or add a .toString();

    also its .equals("...") not .equal("..)

    I checked the value that I get from getSelectedValue with getClass() and it returns that its a String. If I try to cast it or use .toString() I get a redundancy warning. 

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.