Always display scrollbar : JScrollBar « Swing « Java Tutorial






import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.WindowConstants;

public class Main extends JFrame {
  JTextArea textArea;

  public Main() {
    super();
    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    Container contentPane = this.getContentPane();
    textArea = new JTextArea();
    JScrollPane pane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    contentPane.add(pane, BorderLayout.CENTER);
  }

  public static void main(String[] args) {
    JFrame f = new Main();
    f.setSize(300, 200);
    f.setVisible(true);
  }
}








14.48.JScrollBar
14.48.1.The simplest of the bounded range components is the JScrollBarThe simplest of the bounded range components is the JScrollBar
14.48.2.Listening to Scrolling Events with a ChangeListenerListening to Scrolling Events with a ChangeListener
14.48.3.JScrollBar and Adjustment event
14.48.4.Always display scrollbar
14.48.5.Customizing a JScrollBar Look and Feel