#JComboBox not show Items

1 messages · Page 1 of 1 (latest)

gray glen
#

I have a problem with my ComboBox, the issue is that when i add a Item it not show this item on the ComboBox.

package gui.components;

import javax.swing.JComboBox;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import gui.SubjectList;

public class SubjectBox extends JComboBox<String> implements ChangeListener {

    SubjectList subjectList;
    PointPane pointPane;

    public SubjectBox(SubjectList subjectList, PointPane pointPane) {
        this.subjectList = subjectList;
        this.pointPane = pointPane;

        setBounds(1020, 530, 160, 29);
    }

    public void updateList() {
        removeAllItems();
        for (int x = 0; x > subjectList.getSubjects().size(); x++) {
            addItem(subjectList.getSubjects().get(x).getName());
        }
        pointPane.updateList();
    }

    @Override
    public void stateChanged(ChangeEvent event) {
        pointPane.updateList();
    }
}

Your first guess would be maybe: "for-loop not gets executed, because subjectList.getSubjects().size() may be 0 or some"

  • Already tested with a s.o.p if it gets executed, and yes it do

Your second guess would be maybe: "subjectList.getSubjects().get(x).getName() is ""(nothing) and this is why it not show anything"

  • Already tested by just addItem("Test") instate of the name from list, and yes it do not work eather

(I would be very happy on response because its a homework and it would be nice to finish today)

brisk depotBOT
#

<@&987246399047479336> please have a look, thanks.

brisk depotBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If your code is long, or you have multiple files to share, consider posting it on sites like https://pastebin.com/ and share the link instead, that is easier to browse for helpers.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

gray glen
#

But it did work when i only had this: ```Java
package gui.components;

import javax.swing.JComboBox;

public class SubjectBox extends JComboBox<String> {

public SubjectBox(){
    setBounds(1020, 530, 160, 29);
    addItem("Test");
}

}

#

I do not see any big difference to the new one

#

I did > instate of < i hate my life so much