I have this java code:
private JTextArea textArea;
private JButton returnButton;
private ButtonListener buttonListener;
public LessonView() {
setLayout(new BorderLayout());
textArea = new JTextArea();
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setPreferredSize(new Dimension(580, 300));
buttonListener = new ButtonListener();
returnButton = new JButton("Inapoi");
returnButton.addActionListener(buttonListener);
JPanel buttonPanel = new JPanel(new BorderLayout());
buttonPanel.add(returnButton, BorderLayout.WEST);
add(textArea, BorderLayout.NORTH);
add(Box.createVerticalStrut(10), BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
}
I want to add a scrollbar to this textarea. How can I do this? My text is very long and I need a scrollbar. Thank you!