Make JScrollPane to always show scroll bar in Java
Description
The following code shows how to make JScrollPane to always show scroll bar.
Example
import java.awt.Dimension;
import java.awt.FlowLayout;
/*from ww w.jav a 2 s . c o m*/
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("JTextArea Test");
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea textAreal = new JTextArea("from java2s.com", 5, 10);
textAreal.setPreferredSize(new Dimension(100, 100));
JScrollPane scrollPane = new JScrollPane(textAreal, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »