/***************** Simple Scroll Panel Example ************************ *This example uses three scroll panes. It is built on the Simple * Panel Example, so it has a 3 row, 1 column, Grid Layout for the frame. * Flow Layout is used within each of the rows by default, this is why * there is no code defining these. */ import java.awt.*; import javax.swing.*; public class simpleScrollPaneExample extends JFrame{ JPanel row1 = new JPanel(); JPanel row2 = new JPanel(); JPanel row3 = new JPanel(); JTextArea ta1 = new JTextArea(5, 20); JTextArea ta2 = new JTextArea(5, 20); JTextArea ta3 = new JTextArea(5, 20); JScrollPane scrollPane1 = new JScrollPane(ta1,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JScrollPane scrollPane2 = new JScrollPane(ta2,JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane scrollPane3 = new JScrollPane(ta3,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); public simpleScrollPaneExample(){ super("Simple Scroll pane Example"); setSize(600, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridLayout gl = new GridLayout(3, 1); // Layout for the frame setLayout(gl); //////////////////////// Row 1 //////////////////////// row1.add(scrollPane1); // Add scrollpane1 to the panel add(row1); // Add row1 to the frame //////////////////////// Row 2 ///////////////////////// ta2.setLineWrap(true); row2.add(scrollPane2);// Add scrollpane2 to the panel add(row2); // Add row2 to the frame //////////////////////// Row 3 ///////////////////////// ta3.setLineWrap(true); ta3.setWrapStyleWord(true); row3.add(scrollPane3);// Add scrollpane3 to the panel add(row3); // Add row3 to the frame //////////////// Make it all visible //////////////// setVisible(true); } public static void main(String[] args) { simpleScrollPaneExample simpleExample = new simpleScrollPaneExample(); } }