title: Thread sleep until notified from another class
body: <p>Im currently making an infoscreen to display text and pictures on. I have a problem regarding the text part of it.</p>
  
  <p>I have a JFrame as the mainwindow of the displayer. To this frame i add jpanels to display the text and the pictures. then when it's been displayed, i remove the panel again. This part is easy with the pictures because i know how long i want the displayed. for the text however, i need to put the thread to sleep and then wake it back up when my scrollPane has reach the bottom.</p>
  
  <p>Here is where i add the panels </p>
  
  <pre><code>for (File f : files) {
              String fileName = f.getName();
              if (fileName.endsWith(".txt")) {
                  TextPanel txtpan = new TextPanel(f, this, current.getFormat().getFont());
                  add(txtpan);
                  pack();
                  //Input sleep here
                  remove(txtpan);
  
              }
              if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith("bmp")) {
                  AlbumPanel albumpan = new AlbumPanel(connect, f, this, current.getFormat().getPicColor(), current.getFormat().getPicLength());
                  add(albumpan);
                  pack();
                  try {
                      Thread.sleep(current.getFormat().getPicLength() * 1000 + 520);
  
                  } catch (InterruptedException ex) {
                  }
                  remove(albumpan);
              }
  </code></pre>
  
  <p>and this is the textpanel i add</p>
  
  <pre><code>public class TextPanel extends JPanel {
  
  File file;
  JFrame presWin;
  ArrayList&lt;String&gt; lines;
  Font font;
  JTextArea textArea;
  
  public TextPanel(File file, JFrame presWin, Font font) {
      this.file = file;
      this.presWin = presWin;
      this.font = font;
      this.setLayout(new GridBagLayout());
      this.setBackground(Color.white);
      readFile();
      if (!lines.isEmpty()) {
          displayWords();
      }
  
  }
  
  private void readFile() {
      lines = new ArrayList();
      try {
          BufferedReader in = new BufferedReader(new FileReader(file));
          String line;
          while ((line = in.readLine()) != null) {
              lines.add(line);
          }
          in.close();
  
      } catch (Exception ex) {
      }
  }
  
  
  private void displayWords() {
      textArea = new JTextArea();
      textArea.setFont(font);
      textArea.setEditable(false);
      textArea.setLineWrap(true);
      textArea.setWrapStyleWord(true);
      textArea.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
      for (String s : lines) {
          textArea.append(s + System.getProperty("line.separator"));
      }
  
  
      JScrollPane scrollpane = new JScrollPane(textArea);
      scrollpane.setPreferredSize(this.getPreferredSize());
      scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
      scrollpane.setViewportView(textArea);
      System.out.println(scrollpane.getVerticalScrollBar().getMaximum());
      Timer t=new Timer(10, new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              scrollpane.getVerticalScrollBar().setValue(scrollpane.getVerticalScrollBar().getValue()+1);
              if (scrollpane.getVerticalScrollBar().getValue()&gt;=scrollpane.getVerticalScrollBar().getMaximum()) {
                  ((Timer)e.getSource()).stop();
              }
          }
      });
      t.setRepeats(true);
      t.start();
  
  
  
      add(scrollpane);
      repaint();
  }
  
  @Override
  public Dimension getPreferredSize() {
      return new Dimension(presWin.getWidth(), presWin.getHeight());
  }
  </code></pre>
  
  <p>ive tried having a while loop waiting for a boolean in the textpanel</p>