Universal Robots Forum

CheckBox setSelected

Hi guys

I have a very stupid question, but I can’t seem to figure out the cause of my problem.

I’m using a checkbox, and each time there is a mousePressed event, the checkbox value is switched.
For some reason, when I press with my left mouse button, the checkBox will be checked when setSelected(false) is used.
If I press with my right mouse button, the checkbox will be checked when setSelected(true) is used. This is what I obviously want.

Has anybody an idea why this switch happens between left and right mouse button?

Thanks in advance.

Hi,

when using a right click on a checkbox you need to filter the inputEvent of the MouseListener to assure that the functionality of your right click will be executed:

    weavingCB.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            if(mouseEvent.getModifiers() == MouseEvent.BUTTON3_MASK){
                System.out.println("right-clicked...");
            }
        }
    });

if you just want to select/unselect an option with left click a ActionListener should be fine, like so:

    weavingCB = new JCheckBox();
    weavingCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            provider.get().toggleWeaving(weavingCB.isSelected());
        }
    });

i wonder if you really need a right click on polyscope? Do you use sth. like a remote terminal?

Hi

Well the URCap would mostly be used on the Teach Pendant so it could be that this problem would not occur (I haven’t tested it yet). However, if the URCap were to be used with the offline simulator, people would probably use the left mouse button which then would result in the opposite functioning of the checkbox which in turn would give an unprofessional feeling.
Like I mentioned, I’m still new and the mouseListener was based on the one used in the example ‘HelloWorldSwing’ but I’ll have a look at the ActionListener and the difference between both and what it entails for operation on the Teach Pendant.
But to answer your last question, a right click is indeed not needed but it seems odd that with a right click the checkbox response as desired while with a left click the opposite occurs (so unchecked icon if SetSelected(true) ).

Hi,

using an ActionListener ignores the right click completely so your application should be fine :wink: