0

You have chained the constructor with the .add() call, so the end result is a return type of the add() function - which is void. Construct it first, then add the listener.

0

You have chained the constructor with the .add() call, so the end result is a return type of the add() function - which is void. Construct it first, then add the listener.

Interesting, this isn't very important, but would that always make the return type void?

Also, with implementing this interface, would I be able to get rid of my focus listeners and item listeners that I added previously?

I have left the checkbox in as I thought it was a good suggestion. I'm just wondering where setting the InfoObjects background would come into play with the interface. Would I add it in the fireSelectionChanged method?

0

Interesting, this isn't very important, but would that always make the return type void?

It would make the return type be the return type of the last method call in the chain. You have created an object and called a method on it. It's no different than calling a method on a reference to that object that was created previously.

Also, with implementing this interface, would I be able to get rid of my focus listeners and item listeners that I added previously?

I have left the checkbox in as I thought it was a good suggestion. I'm just wondering where setting the InfoObjects background would come into play with the interface. Would I add it in the fireSelectionChanged method?

You InfoObject panel is still going to need to respond to some event like checkbox action performed, mouse clicked, etc. to know when to fire the selection change.

0

It would make the return type be the return type of the last method call in the chain. You have created an object and called a method on it. It's no different than calling a method on a reference to that object that was created previously.
You InfoObject panel is still going to need to respond to some event like checkbox action performed, mouse clicked, etc. to know when to fire the selection change.

This was the example you gave for the mouse click

addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
        setSelected(!selected);
        if (selected) {
            fireSelectionChanged();
        }
    }
});

So if I wanted to just do it by checkbox, would I be able to just do the following:

public void itemStateChanged(ItemEvent e) {
        if(jCheckBox1.isSelected()) {
            fireSelectionChanged();
        } 
    }

Then would I set the backgrounds in my fireSelectionChanged() method, or would it be better to do it in the itemStateChanged instead?

Thanks for all your help Ezzaral and gangsta1903. You both have been quite helpful.

0

I would make the UI changes (ie the background color) in the itemStateChanged method (or actionPerformed would work too). The fireSelectionChanged() method is just responsible for notifying the registered listeners of the change.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.