Results 1 to 6 of 6

Thread: Use of JSlider class

  1. #1
    Join Date
    Dec 2009
    Posts
    59

    Use of JSlider class

    Hello Friends,

    I am BSc(IT) student, with lots of confusion about he classes of java programming. The 'JSlider class' of java sound very complicated than any other class of java. I have to make use of this class in my java project , because of that I need to be aware aware about 'JSlider class'. I wonder if anyone of you provide some details about JSlider class of java. I will really appreciate your any help over JSlider class.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Use of JSlider class

    Hi,

    A JSlider class component that lets the user graphically select a value by sliding a knob within a bounded interval. The slider can show both major tick marks and minor tick marks between them. The number of values between the tick marks is controlled with setMajorTickSpacing and setMinorTickSpacing. For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Use of JSlider class

    Please review following java example of JSlider class, to know about it's use:
    Code:
    public JSlider()
    JSlider aJSlider01 = new JSlider();
    
    public JSlider(int orientation)
    
    JSlider aJSlider01 = new JSlider(JSlider.VERTICAL);
    JSlider bJSlider01 = new JSlider(JSlider.HORIZONTAL);
    
    public JSlider(int min, int max)
    JSlider aJSlider01 = new JSlider(-100, 100);
    
    public JSlider(BoundedRangeModel model)
    DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(3, 0, 1, 31);
    JSlider aJSlider01 = new JSlider(model);
    aJSlider.setOrientation(JSlider.VERTICAL);
    
    public JSlider(int min, int max, int value)
    JSlider aJSlider01 = new JSlider(-100, 100, 0);
    
    public JSlider(int orientation, int min, int max, int value)
    JSlider aJSlider01 = new JSlider(JSlider.VERTICAL, 6, 1, 12);

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Use of JSlider class

    Hello friend,

    A JSlider class of java comprise six various constructors, please refer following:
    1. JSlider(int ortn, int min1, int max1, int val)
    2. JSlider(int min1, int max1, int val)
    3. JSlider(int min1, int max1)
    4. JSlider(int ortn)
    5. JSlider(BoundedRangeModel brmg)
    6. JSlider()

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Use of JSlider class

    Hi,

    Following is the example of JSlider. In which user can select a value for JSlider by using sliding a knob in bounded interval. Please review following code carefully:
    Code:
    import javax.swing.JSlider;
    import javax.swing.event.ChangeListener;
    
    public class SliderDM {
      public static void main(String[] argse) {
        JFrame fv = new JFrame();
        final JSlider slider1 = new JSlider(0, 120, 0);
        fv.setDefvaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        slider1.setPrefverredSize(new Dimension(150, 30));
        slider1.addChangeListener(new ChangeListener() {
          public void stateChanged(ChangeEvent event) {
            int value = slider.getValue();
            if (value == 0) {
              System.out.println("0");
            } else if (value > 0 && value <= 30) {
              System.out.println("value > 0 && value <= 30");
            } else if (value > 30 && value < 80) {
              System.out.println("value > 30 && value < 80");
            } else {
              System.out.println("max");
            }
          }
        });
        fv.add(slider);
        fv.pack();
        fv.setLocationRelativeTo(null);
        fv.setVisible(true);
      }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Use of JSlider class

    Before using JSlider class, you should be aware about following it's various methods:
    • setValueIsAdjusting(boolean bl)
    • setPaintTicks(boolean bll)
    • setPaintTrack(boolean b)
    • setPaintLabels(boolean bl)
    • setModel(BoundedRangeModel newMdl)
    • setMinorTickSpacing(int ns)

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  3. Difference among concrete class and abstract class
    By Roxy_jacob in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 01:22 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,694,193.05494 seconds with 16 queries