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.

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?

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.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.