Java Reference
In-Depth Information
12.
13.
public class DocumentFrame extends SimpleFrame
14.
{
15.
private JTextPane textPane;
16.
private DocumentStatusPanel statusBar;
17.
private DefaultStyledDocument styledDoc;
18.
private EditorKit ediKit;
19.
private Position p1,p2;
20.
21.
private final String filename = "./its/TestData/DocTest.txt";
22.
23.
24.
25.
public DocumentFrame()
{
26.
textPane = new JTextPane();
27.
statusBar = new DocumentStatusPanel();
28.
styledDoc = new DefaultStyledDocument();
29.
textPane.setDocument(styledDoc);
30.
ediKit = textPane.getEditorKit();
31.
JScrollPane sp = new JScrollPane(textPane);
32.
this .getContentPane().add(sp,BorderLayout.CENTER);
33.
34.
this .getContentPane().add(statusBar,BorderLayout.SOUTH);
35.
this .setSize(500,500);
36.
readFile(filename);
37.
DocAtt.createAttributes();
38.
formatText();
39.
try
40.
{
41.
p1 = styledDoc.createPosition(228);
42.
p2 = styledDoc.createPosition(248);
43.
}
44.
catch (Exception ex)
45.
{
46.
System.out.println("Problem creating Positions.");
47.
}
styledDoc.addDocumentListener( new DocListener(statusBar,p1,p2));
48.
statusBar.update("",p1.getOffset(),p2.getOffset());
49.
50.
51.
}
52.
53.
private void readFile(String filename){
try
54.
{
55.
56.
ediKit.read( new FileReader(filename),styledDoc,0);
57.
}
58.
catch (Exception ex)
Search WWH ::




Custom Search