import java.awt.Dimension; import java.awt.FlowLayout; import java.util.Arrays; import java.util.Vector; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; public class MainFrame extends JFrame { DefaultComboBoxModel comboModel; JComboBox combo; Rank[] rankArray = { new Rank(1, "takarító"), new Rank(2, "gondnok"), new Rank(3, "villanyszerelő"), }; Vector rankList = new Vector<>(Arrays.asList(rankArray)); public MainFrame() { setComponent(); setMainFrame(); } private void setComponent() { comboModel = new DefaultComboBoxModel<>(); combo = new JComboBox<>(comboModel); combo.setPreferredSize(new Dimension(100, 32)); rankList.forEach(rank -> { comboModel.addElement(rank.name); }); } private void setMainFrame() { this.add(combo); this.setLayout(new FlowLayout()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(400, 300); this.setVisible(true); } }