I'm just a beginner in Java. Here's my problem :
I created a scrollable field of text with this code (1):
jZone_Text = new JTextPane();
scrollPane = new JScrollPane(jZone_Text);
jZone_Text = new JTextPane();
jPanelRecord.add(scrollPane);
scrollPane.setBounds(20, 70, 550, 190);
scrollPane.setVisible(false);
Then I would like to get the text from my JTextPane and write it in a .txt file So I did this (2) :
try {
FileWriter fw = new FileWriter ("C:\\Users\\Admin\\Desktop\\memo.txt");
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter fichierSortie = new PrintWriter (bw);
fichierSortie.println (jZoneText.getText()+"\n ");
fichierSortie.close();
}catch (IOException e2){
}
But when I try, it creates my memo, but it's blank.
I tried to use the (2) code, and asked to get the text from a textfield which is not in my scrollable pane and it works perfectly..
I think that I can't get the text from a textpane which is in my scrollPane... Is it possible ?
You are creating jZone_Text twice in (1). The second jZone_Text is not the one in the scroll pane thus it is empty. Replace with :
jZone_Text = new JTextPane();
scrollPane = new JScrollPane(jZone_Text);
jPanelRecord.add(scrollPane);
scrollPane.setBounds(20, 70, 550, 190);
scrollPane.setVisible(false);
Also, it is called jTitre_Text in (2), I'm assuming it's a typo