Jump to content

Welcome to DreamBot

VIP Enhancement

Want to upgrade your DreamBot experience? Consider signing up for VIP!
VIP allows you to run as many accounts as you want, view the forums ad-free, receive 10% off all script purchases, and so much more!
Visit the store to learn about all of these great features!

Upgrade to VIP Now
Frequently Asked Questions
  • Are you not able to open the client? Make sure you have Java 8 installed
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
Download the DreamBot client today!
Sign in to follow this  
F00

Issues with ListSelectionEvent

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.

 

Share this post


Link to post
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("..)

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...