Java slider and progress indicator bar

Source: Internet
Author: User

Slider users can use a slider to move back and forth to enter data, which in many cases is intuitive (such as voice control). The process bar displays the status of the relevant data from "empty" to "full", so the user gets a perspective of the state. My favorite example of this program is simply to hook up the slider with the process bar, so when we move the slider, the process bar changes accordingly:

: Progress.java
//Using Progress bars and Sliders
package c13.swing;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
Import javax.swing.event.*;
Import javax.swing.border.*;

public class Progress extends JPanel {
  JProgressBar PB = new JProgressBar ();
  JSlider sb = 
    new JSlider (jslider.horizontal, 0, MB);
  Public Progress () {
    setlayout (new GridLayout (2,1));
    Add (pb);
    Sb.setvalue (0);
    Sb.setpaintticks (true);
    Sb.setmajortickspacing (a);
    Sb.setminortickspacing (5);
    Sb.setborder (New Titledborder ("Slide Me"));
    Pb.setmodel (Sb.getmodel ()); Share Model
    Add (SB);
  }
  public static void Main (String args[]) {
    show.inframe (new Progress (), 200,150);
  }
///:~

JProgressBar is very simple, but JSlider has a number of options, such as methods, large or small marker labels. Note how easy it is to add a border with a caption.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.