title: why won't my text print to my JTextArea?
body: <p>I am calling a method that returns a string (edited text from a webpage) and I want to print that string onto my JTextArea. I know that string I am sending to my JTextArea is correct because it will print correctly to the command line, but will not print to the JTextArea. It must be something I am doing wrong in my adding it to the TextArea. Any help would be appreciated.</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.geom.*;
  import java.awt.event.*;
  
  public class BrowserPanel extends JPanel {
  
  private JTextField textField;
  private String urlText;
  private JTextArea textArea;
  private BrowserPageReader myModel;
  private String pageContent;
  private BrowserFrame myFrame;
  private String pageTitle;
  private String pageBody;
  
  
  
  public BrowserPanel(JTextField myTextField, BrowserPageReader model,
          BrowserFrame frame)
  {
      myFrame = frame;
      myModel = model;
      textField = myTextField;
      textField.addActionListener(new InputHandler());
  
      /*JScrollPane areaScrollPane = new JScrollPane(textArea);
      areaScrollPane.setVerticalScrollBarPolicy(
              JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  
      areaScrollPane.setPreferredSize(new Dimension(250,250));*/
      textArea = new JTextArea(20,40);
      textArea.setEditable(false);
      textArea.setWrapStyleWord(true);
      textArea.setLineWrap(true);
      JScrollPane scroll = new JScrollPane(textArea);
  
      add(scroll);
  }
  
  public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
  
  }
  private class InputHandler implements ActionListener
  {
      public void actionPerformed(ActionEvent e)
      {
           urlText = textField.getText();  
           //textArea.append(urlText);
  
           myModel.setURL(urlText);
           pageTitle = myModel.getTitle();
           myFrame.setTitle(pageTitle);
          pageBody = myModel.getBody();
          textArea.setText(pageBody); 
           System.out.println(pageBody); //This prints out exactly what Im wanting
                                         //  Its just a test             
           textArea.repaint();
      }
  }
  }
  </code></pre>
  
  <p>I'm guessing I maybe need to add something to my paintComponent since my TextArea is in a scrollPane that is attached to my Panel. I just really cant figure out what is wrong. If i put <code>textArea.setText("blah");</code> it does what it should. The variable I am sending in is a very large string, its an entire webpage. Could that be the problem? With the code as is the textArea remains blank and what i'm wanting it to show prints correctly to the command line. HELP!</p>
  
  <p><em>Edit</em> here is the rest of my code</p>
  
  <pre><code>  import javax.swing.*;
  import java.awt.*;
  import java.awt.geom.*;
  
  public class BrowserFrame extends JFrame{
  
  public BrowserFrame()
  {
      BrowserPageReader myModel = new BrowserPageReader();
      setTitle("My Browser");
      Toolkit kit = Toolkit.getDefaultToolkit();
      Dimension screenSize =kit.getScreenSize();
      setSize(screenSize.width/2,screenSize.height-500);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container contentPane = getContentPane();
      JTextField textField = new JTextField(20);
      BrowserPanel myPanel = new BrowserPanel(textField,myModel,this);
      contentPane.add(myPanel);
      contentPane.add(textField,BorderLayout.PAGE_START);
      setVisible(true);
  
  }
  }
  
  
  
  
  
   import javax.swing.*;
  import java.io.*;
  import java.net.*;
  
  public class BrowserPageReader {
  
  private URL myURL;
  //private String webURL;
  private String totalWebContent;
  private String htmlString;
  private String contentToPrint = " ";
  private String urlPath;
  private String urlHost;
  private String pageTitle;
  private String pageBody;
  private String formattedBody;
  
  public void setURL (String webURL)
  {
     try{
          myURL = new URL(webURL);
          urlPath = myURL.getPath();
          urlHost = myURL.getHost();
  
      }
      catch(MalformedURLException e)
      {
          JOptionPane.showMessageDialog(null,"URL is incorrectly formatted");
      }
  }
  
  public void retrieveContent()
  {
      try{
          Socket socket = new Socket(urlHost,80);
          PrintWriter out = new PrintWriter(socket.getOutputStream());
          BufferedReader in = new
                  BufferedReader(new InputStreamReader(socket.getInputStream()));
          out.print("GET " + urlPath + " HTTP/1.1\n");
          out.print("Host: "+ urlHost + "\n");
          out.print("\n");
          out.flush();
          while((totalWebContent = in.readLine()) != null)
          {
              //System.out.println(totalWebContent);
              htmlString = htmlString + totalWebContent;
              //System.out.println(contentToPrint);
          }
          //System.out.println("htmlString\n" + htmlString);
      }
      catch(Exception e){
          e.printStackTrace();
      }
  }
  
  public String getTitle()
  {
         retrieveContent();
        //System.out.println(htmlString);
        pageTitle = htmlString.substring(htmlString.indexOf("&lt;title&gt;")+ 7,
                htmlString.indexOf("&lt;/title&gt;")); 
        return pageTitle;
  }
  
  public String getBody()
  {
      String toDelete;
      String edited;
      retrieveContent();
  
      pageBody = htmlString.substring(htmlString.indexOf("&lt;body")+5,
              htmlString.indexOf("&lt;/body&gt;"));
      toDelete = pageBody.substring(0,pageBody.indexOf('&lt;'));
      edited = pageBody.replace(toDelete,"");
      pageBody = edited
      formattedBody = pageBody.replaceAll("&lt;[^&gt;]*&gt;", "");
      //System.out.println(formattedBody);
      return formattedBody;
  
  }
  </code></pre>