-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScrollpane_JavaTutorial.java
More file actions
30 lines (27 loc) · 985 Bytes
/
Copy pathScrollpane_JavaTutorial.java
File metadata and controls
30 lines (27 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.Scanner;
import javax.swing.JTextArea;
/**
*
*@author Vincent
*/
public class ScrollPane {
public static void main(String[] args) throws FileNotFoundException{
Scanner user_input = new Scanner(System.in);
JFrame window = new JFrame("JScrollBar example");
String all = new Scanner(new File("textExample.txt")).useDelimiter("\\A").next();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextArea textArea = new JTextArea(10, 20);
JScrollPane scroll = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
textArea.setText(all);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
window.add(scroll);
window.setSize(500, 500);
window.setVisible(true);
window.setLocationRelativeTo(null);
}
}