import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
public class JScrollPane_test {
public static void main(String[] args) {
JScrollPane_Test();
}
private static void JScrollPane_Test() {
JFrame frame = new JFrame("Test JScrollPane");
frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE);
frame.setSize(500, 500);
frame.setLayout(null);
JPanel panel = new JPanel(null);
panel.setBounds(200, 200, 200, 200);
Border border = new LineBorder(Color.ORANGE, 4, true);
panel.setBorder(border);
JTextArea textArea1 = new JTextArea("Test1 Test2 Test3 Test4 Test5 Test6 Test7 Test8 Test9 Test10 Test11 Test12 Test13 Test14 Test15 Test16 Test17 Test18 Test19 Test20 Test21 Test22 Test23 Test24 Test25 Test26 Test27 Test28 Test29 Test30 Test31 Test32 Test33 Test34 Test35 Test37 Test38 ");
textArea1.setLineWrap(true);
textArea1.setWrapStyleWord(true);
textArea1.setFocusable(false);
JTextArea textArea2 = new JTextArea("Test1 Test2 Test3 Test4 Test5 Test6 Test7 Test8 Test9 Test10 Test11 Test12 Test13 Test14 Test15 Test16 Test17 Test18 Test19 Test20 Test21 Test22 Test23 Test24 Test25 Test26 Test27 Test28 Test29 Test30 Test31 Test32 Test33 Test34 Test35 Test37 Test38 ");
textArea2.setLineWrap(true);
textArea2.setWrapStyleWord(true);
textArea2.setFocusable(false);
JScrollPane scroll1 = new JScrollPane();
scroll1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll1.setBounds(20, 20, 100, 100);
scroll1.getViewport().add(textArea1);
JScrollPane scroll2 = new JScrollPane();
scroll2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scroll2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll2.setBounds(20, 20, 100, 100);
scroll2.getViewport().add(textArea2);
panel.add(scroll2);
frame.add(scroll1);
frame.add(panel);
frame.setVisible(true);
}
}