title: How to dynamically update JLabel on changed text?
body: <p>My JLabel starts out with a variable that is 0 when JLabel is drawn. Another Thread increases this value continually and I want to update the Label. </p>
  
  <p>If possible I don't want the thread to access the label.
  (gm.getPlayerByListIndex(index).getAlk()) gets updated</p>
  
  <pre><code>    createPlayer.addActionListener(new ActionListener() {
  
          @Override
          public void actionPerformed(ActionEvent e) {
              boolean checked = checkInputs(nameInput, difficultyInput);
              if (checked) {
                  String playername = getInput(nameInput);
                  addPlayerToMainWindow(gm.getRegisteredPlayers().size(), playername);
                  gm.createPlayer(playername, Integer.parseInt(getInput(difficultyInput)));
                  dialog.dispose();
                  JLabel alkLabel = new JLabel(Integer.toString(gm.getPlayerByListIndex(index).getAlk()));
                  window.getWindow().getContentPane().add(alkLabel);
                  alkLabel.setVisible(true);
                  alkLabel.setBounds(160, (120 * index) + 50, 100, 50);
  
              }
          }
  
      });
  </code></pre>
  
  <p>Thread that increases Valuse:</p>
  
  <pre><code>public class Dispenser extends Thread {
  
       List&lt;Player&gt; players = GameManager.getInstance().getRegisteredPlayers();
  
      public void run() {
  
         while (true) {
             System.out.println("alive");
             try {
                 for (Player p : players) {
                     p.setAlk(p.getAlk() + p.getDifficulty()); // TODO too hard
                 }
              } catch (ConcurrentModificationException e) {
                  System.out.println("playerlist in use, retry");
              }
              try {
                 sleep(1000); // TODO too short
              } catch (InterruptedException e1) {
                 // TODO Auto-generated catch block
                 e1.printStackTrace();
             }
          }
     }
  
  }
  </code></pre>