title: Adding a text area to a tabbed pane in java
body: <p>I have two files that I need to display in a program. I need to use JTabbedPane and each file should be displayed in its own tab. I can make the text appear in the tab, but the scroll bar won't appear, so I can't see all of the information in the file. How do I add the scroll bar to the text area?</p>
  
  <p>I made one method that creates a panel with the text in it (this is for one file). Then, I made another method that has JTabbedPane and I added the panel to a tab.</p>
  
  <p>Panel method:</p>
  
  <pre><code>private void makeTextPanel() throws IOException
  {
      textPanel = new JPanel();        
  
      textArea = new JTextArea();
      textArea.setEditable(false);
  
      //width: 770 height: 1000
      textAreaDimensions = new Dimension(TEXT_AREA_WIDTH, TEXT_AREA_HEIGHT);
      textArea.setPreferredSize(textAreaDimensions);       
  
      BufferedReader inputFile = new BufferedReader(new FileReader(FILE_ONE));
      String lineOfText = inputFile.readLine();
  
      while(lineOfText != null)
      {
          textArea.append("\n" + lineOfText);
          lineOfText = inputFile.readLine();
      }
  
      // Add a scroll bar
      scrollPane = new JScrollPane(textArea);
  
      // Add the text area and scroll bar to the panel
      textPanel.add(textArea);
      textPanel.add(scrollPane);
  }
  </code></pre>
  
  <p>Tabbed pane method:</p>
  
  <pre><code>private void makeTabbedPane() throws IOException
  {
      frame = new JFrame("Project");   
  
      tabbedPane = new JTabbedPane();
      frame.add(tabbedPane, BorderLayout.PAGE_START);
  
      // add panel to the tab
      makeTextPanel();
      tabbedPane.addTab("Tab 1", textPanel);  
  
      // dimensions
      frameDimensions = new Dimension(FRAME_WIDTH, FRAME_HEIGHT);
      frame.setPreferredSize(frameDimensions);
  
  
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
  }
  </code></pre>
  
  <p>To reiterate:</p>
  
  <ul>
  <li>How do I make the scroll bar visible?</li>
  <li>I set the height of the text area to 1000. Will the scroll bar be able to scroll through everything? If not, how do I set the height of the text area to fit everything in the file?</li>
  </ul>