Sliders, Progress Bars and Toolbars

Site Admin · 11 Sep 2026 · 2 views

JSlider

A slider picks a value from a range. Listen to its change events to react:

JSlider volume = new JSlider(0, 100, 40);
volume.addChangeListener(e -> value.setText("Volume: " + volume.getValue()));

Swing JSlider demo

JProgressBar

Displays task progress. Set the value between its minimum and maximum:

JProgressBar bar = new JProgressBar(0, 100);
bar.setValue(65);
bar.setStringPainted(true);

Swing JProgressBar demo

JScrollPane

Provide scrolling for large components without manual work:

JTextArea big = new JTextArea(10, 30);
add(new JScrollPane(big));

Swing JScrollPane demo

JToolBar

A draggable strip of buttons for quick actions:

JToolBar tb = new JToolBar();
tb.add(new JButton("New"));
tb.add(new JButton("Open"));
tb.addSeparator();
tb.add(new JButton("Save"));

Swing JToolBar demo

Swing toolbar output

Key Points

  • Sliders and progress bars rely on bounded range models.
  • Wrap big components in JScrollPane to get scrollbars automatically.
  • Toolbars group actions into a floatable strip.
Share this post:

Comments (0)

Please login or register to comment.