title: Can't change text in JTextArea in Java
body: <p>I created a class that extends another class, so that I can get the JTextArea from the main class. I'm not getting any errors for some reason. When I get the text of the JTextArea it is the text that I changed it to, but it isn't showing up on the JTextArea. I am trying to open a txt file and get the text from the file and put it on the JTextArea. Can anyone please make any suggestions why this might not work? </p>
  
  <pre><code> public JMenuItem open(){
          open.addActionListener (new ActionListener (){
              public void actionPerformed (ActionEvent e){
                  jta.setText("");
                  fileChooser=new JFileChooser();
                  fileChooser.setDialogTitle("Choose a file...");
                  int response=fileChooser.showOpenDialog(null);
  
                  if(response==JFileChooser.APPROVE_OPTION){
                      String filePath=fileChooser.getSelectedFile().toString();
                      try{
                          File userFile=new File(filePath);
                          Scanner scan=new Scanner(userFile);
                          String text="";
                          while(scan.hasNextLine()){
                              text+=scan.nextLine();
                              jta.replaceSelection(text);
                          }
                      }catch (IOException e1){
                          e1.printStackTrace();
                      }
                  }
  
              }
          });
          open.setAccelerator(KeyStroke.getKeyStroke('O', KeyEvent.CTRL_DOWN_MASK));
          return open;
      }
  </code></pre>
  
  <p>This ^^^ is used like so:</p>
  
  <pre><code>public class FileMenu extends MenuBar{
      private JMenu file=new JMenu("File");
      JMenuItem New= new JMenuItem("New");
      JMenuItem open= new JMenuItem("Open file...");
      JMenuItem save= new JMenuItem("Save");
      JMenuItem saveAs= new JMenuItem("Save As...");
      JMenuItem close= new JMenuItem("Exit");
      public JFileChooser fileChooser;
      FileActions fileActions;
  
      public FileMenu(){
  
      }
  
      public JMenu menu(){
          fileActions=new FileActions();
          file.add(fileActions.newWindow());
          file.add(fileActions.open());
          file.addSeparator();
          file.add(save);
          file.add(saveAs);
          file.addSeparator();
          file.add(close);
  
          save.setAccelerator(KeyStroke.getKeyStroke('S', KeyEvent.CTRL_DOWN_MASK));
          saveAs.setAccelerator(KeyStroke.getKeyStroke('E', KeyEvent.CTRL_DOWN_MASK));
          close.setAccelerator(KeyStroke.getKeyStroke('Q', KeyEvent.CTRL_DOWN_MASK));
  
          mb.add(file);
          return file;
      }
  }
  </code></pre>
  
  <p>This is where the JTextArea is created:</p>
  
  <pre><code>public class Frame {
      static final String title="Simple Text Editor";
      static final int width=650;
      static final int height=700;
      public JFrame frame=new JFrame(title);
      public JTextArea jta=new JTextArea();
      JScrollPane scrollPane=new JScrollPane(jta);
  
      public void create(){
          //JFrame
          frame.setSize(width,height);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.setLocationRelativeTo(null);
  
          // JMenuBar
          MenuBar menuBar=new MenuBar();
          frame.add(menuBar.menuBar(), BorderLayout.NORTH);
  
          jta.setText("Well this works...");
          // JTextArea
          jta.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
          frame.add(scrollPane, BorderLayout.CENTER);
      }
  }
  </code></pre>