java - Getting text from a text pane in a scrollpane -
I'm just starting out in Java here's my problem:
I have this code with A scrollable field text is created (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 (wrong);
Then I want to get the text from my JTextPane and write it in the .txt file so I made it (2) :
Ex> try {FileWriter fw = new FileWriter ("C: \\ user \\ administrator \\ desktop \\ memo.txt"); Buffett Vitter BW = New Baffed Vitter (FW); Printritter feature sortie = new print-viter (bw); Feature softy.printLN (jZoneText.getText () + "\ n"); FichierSortie.close (); } Hold (IOException e2) {}
But when I try, it makes my memo, but it is empty.
I tried to use the code (2), and asked to get text from a text file that is not in my scrollable panel and it works perfectly.
I think I can not get the text from a text bar which is in my scrollpad ... is it possible?
You are creating jZone_Text (1) twice. The second jejun-tag is not in the scroll panel, so 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 (wrong);
In addition, it is called jTitre_Text in (2), I'm assuming that it is a typo
Comments
Post a Comment