Java Reference
In-Depth Information
File: its/Scrolling/TextDisplayScrollFrame.java
1. package its.Scrolling;
2.
3. import its.SimpleFrame.SimpleFrame;
4. import java.io.File;
5. import java.io.FileReader;
6. import java.io.IOException;
7. import java.awt.BorderLayout;
8. import javax.swing.JEditorPane;
9. import javax.swing.JScrollPane;
10.
11. public class TextDisplayScrollFrame extends SimpleFrame
12. {
13.
private JEditorPane TextDisplayPanel;
14.
15.
public TextDisplayScrollFrame(String filename)
16.
{
17.
18.
TextDisplayPanel = new JEditorPane();
19.
20.
JScrollPane scrollPane = new JScrollPane(TextDisplayPanel);
21.
this .getContentPane().add(scrollPane,BorderLayout.CENTER);
22.
23.
File readfile = new File(filename);
24.
25.
try {
26.
FileReader fr = new FileReader(readfile);
27.
TextDisplayPanel.read(fr, null );
28.
} catch (IOException e){
29.
System.out.println("Problems opening or reading "
+readfile.getName());
30.
}
31. }
32. }
11.2
Scrolling panels
If we use the default policy HORIZONTAL_SCROLLBAR_AS_NEEDED for the text com-
ponent, the runtime system automatically determines the size of the area that is
filled with text. The scroll bars are shown only if that area does not fit into the
viewport. Using the default policy with panels will make the scroll bars appear
when the area specified with a setPreferredSize command does not fit into the
viewport.
Search WWH ::




Custom Search