I am building a menu gui for this application. The user enters the number of players they have and then when they hit next the window is supposed to display entry boxes for their names based on the number of players. I am having trouble with the scroll pane I'm attempting to display them in, it just isn't displaying anything.
Here is my code:
public void enterPlayersMenu(){ playersArray = new JTextField[numberPlayers]; players = new String[numberPlayers]; JPanel enterPlayersPane = new JPanel(); enterPlayersPane.setLayout(null); for (int i = 0; i < numberPlayers; i++){ playersArray[i] = fieldAskStr(enterPlayersPane, "Player " + (i + 1), null, 0, i * 20); } JScrollPane enterPlayersScrollPane = new JScrollPane(enterPlayersPane); enterPlayersScrollPane.setLayout(new FlowLayout()); enterPlayersScrollPane.setBounds(0,0,WIDTH,HEIGHT); enterPlayersScrollPane.createVerticalScrollBar(); panel.add(enterPlayersScrollPane); }
and here is the fieldAskStr() method:
public JTextField fieldAskStr(JComponent panel, String labelStr, String seed, int posX, int posY){ JLabel label = new JLabel(labelStr); label.setBounds(posX, posY, labelStr.length() * 6, 20); panel.add(label); JTextField textField = new JTextField(20); textField.setBounds(WIDTH/2, posY, WIDTH/2, 20); textField.setDocument(new JTextFieldLimit(20)); if (seed != null){textField.setText(seed);} panel.add(textField); return textField; }
The code returns an error on the enterPlayersScrollPane.setLayout(new FlowLayout()), that i can only get rid of by deleting the line entirely. I think my problem may be in the layout manager I am using. I just don't know what it is or how to fix it.