There is a JScrollPane that contains a JTextArea. Need to get text from JTextArea, how can this be done? The structure is as follows:
JTextArea area = new JTextArea(String.valueOf(res)); JScrollPane pane = new JScrollPane(area); pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); choiceFile.addTab(workFile.getName(), pane); choiceFile.setSelectedIndex(i); The choiceFile is JTabbedPane. JScrollPane is a scrollbar to which text is added from JTextArea, which was counted from the file selected by the user. workFile is the file that the user has just selected. res is a string containing the information read from the file. Since the JTabbedPane is present, the JTextArea exists for quite a short time (only inside the Open method). How can I get text from JScrollPane? It all looks like this: 
Before that, text reading was easy, since the JTabbedPane contained a JTextArea and it went like this:
int j = 0; String text = ((JTextArea)choiceFile.getComponentAt(choiceFile.getSelectedIndex())).getText(); JTextArea area = new JTextArea(); area.setText(text); int l = area.getLineCount(); ArrayList<String> allString = new ArrayList<>(); String allText = text; for (String buffer : allText.split("\n")) { allString.add(buffer); } while (j < allString.size()) { out.append(allString.get(j) + "\r\n"); j++; } Where out is a BufferedWriter containing information about where to write the received information.