Search code examples
javaswinguser-interfacejcomponent

Java beginner question - add multiple items to screen


I'm a complete beginner trying to learn Java as my first language. When I'm adding TYPE and Skills to the window, only the one added last (in this case, skills) appears. How do I get both to appear?

Thanks, Ravin

public class Funclass extends JFrame{
    FlowLayout layout = new FlowLayout();
    String[] Skillz = {"Analytical", "Numerical", "Leadership", 
          "Communication", "Organisation", "Interpersonal"};
    public Funclass(){
        super("Title Bar");
        JTextField Company = new JTextField("Company Name");
        JComboBox TYPE = new JComboBox();
        JList Skills = new JList(Skillz);
        TYPE.addItem("Choose which type of firm");
        TYPE.addItem("Consultancy");
        TYPE.addItem("Tech");
        Skills.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        add(TYPE);
        add(Skills);
    }
}

Solution

  • You forgot to add

    setLayout(layout);
    

    in the constructor.