Set up JScrollBar for Scroll Pane - Java Swing

Java examples for Swing:JScrollPane

Introduction

You can set a policy for a JScrollBar component when you create it

Use one of several constants in the ScrollPaneConstants interface:

  • HORIZONTAL_SCROLLBAR_ALWAYS
  • HORIZONTAL_SCROLLBAR_AS_NEEDED
  • HORIZONTAL_SCROLLBAR_NEVER
  • VERTICAL_SCROLLBAR_ALWAYS
  • VERTICAL_SCROLLBAR_AS_NEEDED
  • VERTICAL_SCROLLBAR_NEVER

These constants are used with the JScrollPane (Object, int, int) constructor.

Here's an example:

JScrollPane scroller = new JScrollPane (textBox, 
   VERTICAL_SCROLLBAR_ALWAYS, 
   HORIZONTAL_SCROLLBAR_NEVER);

Related Tutorials