I'm currently learning the javax.swing
package. Created a JFrame
that currently has a JMenuBar
and a JTextArea
. I've been trying to add a scrollbar to my application using JScrollPane
but am having no luck. The scrollbar never appears with my code and I'm not sure what's the issue.
import java.awt.*;
import javax.swing.*;
class WordProcessor {
JFrame frame;
JMenuBar menu;
JTextArea textArea;
JScrollPane scrollPane;
public WordProcessor() {
scrollPane = new JScrollPane(frame);
//Create Frame for application
frame = new JFrame("Word Processor");
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.decode("#FFC0CB"));
menuBar();
textArea();
scrollPane();
}
public void scrollPane() {
scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.add(scrollPane);
}
For clarification, I'm trying to add a scrollbar for the whole window — not the text area.