import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.*; public class ScrollPaneExample extends JFrame{ JTextArea textArea = new JTextArea(30,30); JScrollPane scrollPane; // constructor public ScrollPaneExample() { textArea.setText("The oboe is a double reed musical instrument of the woodwind family. " + "In English, prior to 1770, the instrument was called \"hautbois\", \"hoboy\", or " + "\"French hoboy\". The spelling \"oboe\" was adopted into English ca. 1770 from " + "the Italian oboč, a transliteration in that language's orthography of the 17th-century " + "pronunciation of the French word hautbois, a compound word made of haut (\"high, loud\") " + "and bois (\"wood, woodwind\"). A musician who plays the oboe is called an oboist."); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setEditable(false); scrollPane = new JScrollPane(textArea); this.add(scrollPane, BorderLayout.CENTER); } public static void main(String args[]) { JFrame frame = new ScrollPaneExample(); frame.setSize(200,200); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }