help: JTextPane
I need to add text from file (12.txt - any text data here) into JTextPane. Here is code. If I print like: System.out.println, then works good, but into the JTextPane is only the last line. Pleasse help.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class One {
public String filename = new String();
public static JTextPane prikaz = new JTextPane ();
public One (){
JFrame window = new JFrame ("dddsds");
Container vsebnik = window.getContentPane();
vsebnik.add (prikaz, BorderLayout.CENTER);
window. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(600, 500);
window.setVisible (true);
}
public static void main (String args[]){
try {
UIManager.setLookAndFeel (
UIManager.getCrossPlatformLookAndFeelClassName() );
}
catch (Exception k) {}
One mfc = new One();
readMyFile();
}
static void readMyFile() {
String record = null;
try {
FileReader fr = new FileReader("12.txt");
BufferedReader br = new BufferedReader(fr);
record = new String();
while ((record = br.readLine()) != null) {
System.out.println(record);
prikaz.setText(record);
}
} catch (IOException l) {
// catch possible io errors from readLine()
System.out.println("Uh oh, got an IOException error!");
l.printStackTrace();
}
}
}

