Hello, im working on a battleship game in java and i'm currently working with the graphical part of the program. Im trying to make a JPanel that i will fill with JComboBox. The JComboBox will have some preset values 0-7 that allows me to select different positions in an 2d array that i will assign with boats. However i cant get it to show. Keep in mind that my code isn't completely done and this is only a window to set player information.
My code:
import java.awt.Container; import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; public class WelcomeWindow extends JFrame { private Container contentPanel; private JButton okButton; public WelcomeWindow(){ configureFrame(); initiateInstanceVariables(); addComponentsToFrame(); } private void configureFrame(){ this.setSize(400, 600); this.setLocationRelativeTo(null); this.setResizable(false); this.setTitle("Add Player"); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); } private void addComponentsToFrame(){ JPanel dropDownPanel = new JPanel(); dropDownPanel.setLayout(null); dropDownPanel.setBorder(BorderFactory.createTitledBorder("Pos for ships")); this.contentPanel.add(this.okButton); JPanel aPanel= buildComboBoxes(); dropDownPanel.add(aPanel); this.contentPanel.add(dropDownPanel); } private void initiateInstanceVariables(){ this.okButton = new JButton("Ok"); this.okButton.setBounds(150, 500, 100, 40); this.contentPanel = this.getContentPane(); this.contentPanel.setLayout(null); } private JPanel buildComboBoxes(){ JPanel comboPanel = new JPanel(); comboPanel.setLayout(new GridLayout(4,2,00,10)); comboPanel.setBounds(0,100,400,200); String[] avaliblePos = {"0","1","2","3","4","5","6","7"}; JComboBox xyPos = null; for(int i=0;i<avaliblePos.length;i++){ xyPos = new JComboBox(avaliblePos); } comboPanel.add(xyPos); return comboPanel; } }