By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Updating a JLabel to a JPanel

P: 6
I have a method addPlayer that's supposed to add a JLabel to a JPanel and update the JPanel. The JLabel is just a label with a player's name in it. The code I've wrote doesn't work and I'm not sure why. Any help would be greatly appreciated

Expand|Select|Wrap|Line Numbers
  1.     int playerCount = 0;
  2.     private void addPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
  3.         String name = nameTextField.getText();
  4.         Object color = colorComboBox.getSelectedItem();
  5.         Object type = (String)typeComboBox.getSelectedItem();
  6.  
  7.         Player player = new Player(name);
  8.         game.players.add(player);
  9.         playerCount++;
  10.  
  11.         if (playerCount < 6){
  12.             JLabel newLabel = new JLabel(name);
  13.             playersPanel.add(newLabel);
  14.             playersPanel.validate();
  15.             playersPanel.repaint();          
  16.         }
  17.      }
  18.  
  19.  
Nov 17 '07 #1
Share this Question
Share on Google+
1 Reply


P: 6
nevermind, figured it out
Nov 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.