Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

GUI checkbox wont disable other GUI options

Featured Replies

Sadly have spent about 2 hours trying to get a check box in my gui to disable other options. Basically what I need it to do is, If checkbox is enabled, enable the spinner.

 

Here's the code I have:

		 chckbxAutoGE.addItemListener(new ItemListener() {
			  @[member=Override]
			  public void itemStateChanged(ItemEvent e) {
			    if(e.getStateChange() == ItemEvent.SELECTED){
			    	spinnerHides.setEnabled(true);
			    }
			    if(e.getStateChange() == ItemEvent.DESELECTED){
			    	spinnerHides.setEnabled(false);
			    }
			  }
			 });

any help is highly appreciated.

Maybe you're going the right way, but what I did is I used ActionListener instead of a ItemListener and everything worked fine

    private void muleCheckActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if (muleCheck.isSelected()) {
        	fisherCheck1.setSelected(false);
        	fisherPanel.setEnabled(false);
        	mulePanel.setEnabled(true);
        	
        	for (java.awt.Component comp : mulePanel.getComponents()) {
        		comp.setEnabled(true);
        	}
        	for (java.awt.Component comp : fisherPanel.getComponents()) {
        		comp.setEnabled(false);
        	}
        }
    }   

This disables/enables one of the two JPanels and all of it's components depending on which checkbox is selected. Code is for one checkBox only

  • Author

Maybe you're going the right way, but what I did is I used ActionListener instead of a ItemListener and everything worked fine

    private void muleCheckActionPerformed(java.awt.event.ActionEvent evt) {                                          
        if (muleCheck.isSelected()) {
        	fisherCheck1.setSelected(false);
        	fisherPanel.setEnabled(false);
        	mulePanel.setEnabled(true);
        	
        	for (java.awt.Component comp : mulePanel.getComponents()) {
        		comp.setEnabled(true);
        	}
        	for (java.awt.Component comp : fisherPanel.getComponents()) {
        		comp.setEnabled(false);
        	}
        }
    }   

This disables/enables one of the two JPanels and all of it's components depending on which checkbox is selected. Code is for one checkBox only

 

Thanks for your quick response. I'm still new to this whole GUI thing so I'm easily confused here. This is my whole GUI class. 

 

http://pastebin.com/ji1gyg6N

 

and what it looks like:

 

http://puu.sh/t1mZK/f11021eade.png

 

It's probably setup odd (first gui) but has worked well for me up until this point.

Edited by Mushphang

Thanks for your quick response. I'm still new to this whole GUI thing so I'm easily confused here. This is my whole GUI class. 

 

http://pastebin.com/ji1gyg6N

 

and what it looks like:

 

http://puu.sh/t1mZK/f11021eade.png

 

It's probably setup odd (first gui) but has worked well for me up until this point.

        /*chckbxAutoGE.addActionListener(e -> {
            if (chckbxAutoGE.isSelected()) {
                spinnerHides.setEnabled(true);
            } else {
                spinnerHides.setEnabled(false);
            }
        });*/

Why is this part commented out? Should work

  • Author
        /*chckbxAutoGE.addActionListener(e -> {
            if (chckbxAutoGE.isSelected()) {
                spinnerHides.setEnabled(true);
            } else {
                spinnerHides.setEnabled(false);
            }
        });*/

Why is this part commented out? Should work

 

 

Doesn't work for some reason :( Tried multiple things in the 2 + hours I spent on this.

Didn't read your code mb lmao

Edit: after actually reading your code, could you not just do something like this?

chckbxAutoGE.addActionListener(e -> spinnerHides.setEnabled(!spinnerHides.isEnabled()));

Edited by Hydra

Works fine when I run your code. Make sure you don't have an old cached version of your Jar interfering somewhere

  • Author

Didn't read your code mb lmao

Edit: after actually reading your code, could you not just do something like this?

chckbxAutoGE.addActionListener(e -> spinnerHides.setEnabled(!spinnerHides.isEnabled()));

 

Haha all good, and still no luck. Could it be possible it has something to do with the main start button action listener? Does it matter what order the listeners are in?

Works fine when I run your code. Make sure you don't have an old cached version of your Jar interfering somewhere

 

O lord, checking now.

Works fine when I run your code. Make sure you don't have an old cached version of your Jar interfering somewhere

 

I can't seem to find anything.. What do you specifically mean?

  chckbxAutoGE.addItemListener(new ItemListener() {
            @[member='Override']
            public void itemStateChanged(ItemEvent e) {
                if(e.getStateChange() == ItemEvent.SELECTED){
                    spinnerHides.setEnabled = true;
                }else{
                    spinnerHides.setEnabled = false;
                }
            }
        });

This should work. Literally from my project, just renamed to your scenario.  This should work, else you will need to see what you've done wrong. There is something in your project that is disallowing this to work.

 

If the first condition isn't met, then it go false. 

Edited by Satire

  • Author
  chckbxAutoGE.addItemListener(new ItemListener() {
            @[member='Override']
            public void itemStateChanged(ItemEvent e) {
                if(e.getStateChange() == ItemEvent.SELECTED){
                    spinnerHides.setEnabled = true;
                }else{
                    spinnerHides.setEnabled = false;
                }
            }
        });

This should work. Literally from my project, just renamed to your scenario.  This should work, else you will need to see what you've done wrong. There is something in your project that is disallowing this to work.

 

If the first condition isn't met, then it go false. 

 

 

Tried this and no luck again, made a fresh class file on another script. This is the code and still doesn't disable the other checkbox


import javax.swing.JCheckBox;
import javax.swing.JFrame;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


public class SettingsGUI {
	public static void Window(main m) {
		JFrame jFrame = new JFrame("Curtidor");
		jFrame.setSize(261, 419);
		jFrame.setResizable(false);
		jFrame.getContentPane().setLayout(null);

		JCheckBox chckbxNewCheckBox = new JCheckBox("New check box");
		chckbxNewCheckBox.setBounds(40, 75, 97, 23);
		jFrame.getContentPane().add(chckbxNewCheckBox);

		JCheckBox chckbxNewCheckBox_1 = new JCheckBox("New check box");
		chckbxNewCheckBox_1.setBounds(40, 146, 97, 23);
		jFrame.getContentPane().add(chckbxNewCheckBox_1);

		jFrame.setVisible(true);

		chckbxNewCheckBox.addItemListener(new ItemListener() {
			@[member=Override]
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					chckbxNewCheckBox_1.setEnabled(true);
				} else {
					chckbxNewCheckBox_1.setEnabled(false);
				}
			}
		});
	}
}

  • Author

Well everyone.. I've spent hours tonight on this. Problem is solved. I literally was right click testing the gui in eclipse on the design preview. It didn't come across my mind (still being new to java) that apparently the action listeners don't do anything on the preview.. After officially testing on osbot it works just find :^). 

 

Me:

 

 

01a.jpg

This makes me both chronically depressed & very happy that you found the answer

Well everyone.. I've spent hours tonight on this. Problem is solved. I literally was right click testing the gui in eclipse on the design preview. It didn't come across my mind (still being new to java) that apparently the action listeners don't do anything on the preview.. After officially testing on osbot it works just find :^). 

 

Me:

 

 

01a.jpg

I guess that's a lesson learned for the future :) 

Glad you got it working.

Sadly have spent about 2 hours trying to get a check box in my gui to disable other options. Basically what I need it to do is, If checkbox is enabled, enable the spinner.

 

Here's the code I have:

		 chckbxAutoGE.addItemListener(new ItemListener() {
			  @[member='Override']
			  public void itemStateChanged(ItemEvent e) {
			    if(e.getStateChange() == ItemEvent.SELECTED){
			    	spinnerHides.setEnabled(true);
			    }
			    if(e.getStateChange() == ItemEvent.DESELECTED){
			    	spinnerHides.setEnabled(false);
			    }
			  }
			 });

any help is highly appreciated.

 

Edit: my bad, didn't realize this was solved

Edited by Imateamcape

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.