Java 8 JSlider - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JSlider class.

This code example shows how to use the following methods:addChangeListener, setMajorTickSpacing, setSnapToTicks
     
    /** 
     * Create a new ScaleSelector. 
     */ 
    public ScaleSelector() { 
        slider = new JSlider(1,10,1);
        value  = new JLabel("x1");
        size = new JLabel("   ");
        preview = new ImagePanel();
         
        value.setPreferredSize(new Dimension(25,10));
        size.setHorizontalAlignment(JLabel.CENTER);
        slider.setMajorTickSpacing(1);
        slider.setSnapToTicks(true);
        slider.addChangeListener(this);
         
        setLayout(new BorderLayout());
         
        Box b1 = new Box(BoxLayout.X_AXIS);
        b1.add(Box.createHorizontalStrut(5));
7
CodeRank
This code example shows how to use the following methods:addChangeListener, setMajorTickSpacing, setMinorTickSpacing, setPaintLabels, setPaintTicks
        this.combo3 = new JComboBox();
        populateTextAnchorCombo(this.combo3);
        this.combo3.setActionCommand("combo3.changed");
        this.combo3.addActionListener(this);
        controls.add(this.combo3);
        this.slider = new JSlider(SwingConstants.VERTICAL, 0, 360, 0);
        this.slider.setMajorTickSpacing(45);
        this.slider.setMinorTickSpacing(5);
        this.slider.setPaintLabels(true);
        this.slider.setPaintTicks(true);
        this.slider.setPaintTrack(true);
        this.slider.addChangeListener(this);
        content.add(controls, BorderLayout.NORTH);
        content.add(this.slider, BorderLayout.WEST);
        this.drawStringPanel2 = new DrawStringPanel("Rotated Text", true);
        content.add(this.drawStringPanel2);
        return content;
    } 
 
    /** 
7
CodeRank
This code example shows how to use the following methods:setMajorTickSpacing, setMaximum, setMinimum, setMinorTickSpacing, setPaintLabels
		if(min==max){
			min =-1;
			max =2;
		} 
		 
		final JSlider slider = new JSlider();
		//slider.setBorder(BorderFactory.createTitledBorder(title)); 
		//Component[] c = slider.getComponents(); 
		slider.setMinimum(min);
		//slider.setM 
		slider.setMaximum(max);
		slider.setMajorTickSpacing((max-min)/5);
		slider.setMinorTickSpacing((max-min));
		 
		slider.setPaintTicks(true);
		slider.setPaintLabels(true);
		/*slider.addChangeListener(new ChangeListener() { 
			@Override 
			public void stateChanged(ChangeEvent e) { 
				System.out.println(title + ": " + slider.getValue()); 
			} 
6
CodeRank
This code example shows how to use the following methods:setMajorTickSpacing, setMaximum, setMinimum, setMinorTickSpacing, setPaintLabels
		add( sliders[2] );
		//add( sliders[3] ); 
	} 
	 
	protected JSlider createSlider(final String title, int min, int max){
		final JSlider slider = new JSlider();
		//slider.setBorder(BorderFactory.createTitledBorder(title)); 
		 
		/* 
		Component[] c = slider.getComponents(); 
		for(Component ci: c){ 
			System.out.println(ci); 
		}*/ 
		slider.setMinimum(min);
		slider.setMaximum(max);
		slider.setMajorTickSpacing(20);
		slider.setMinorTickSpacing(5);
		slider.setPaintTicks(true);
		slider.setPaintLabels(true);
		/*slider.addChangeListener(new ChangeListener() { 

6
CodeRank
This code example shows how to use the following methods:setMajorTickSpacing, setMaximum, setMinimum, setMinorTickSpacing, setPaintTicks
	 * @return JSlider 
	 */ 
	public static JSlider buildSlider(int min, int max, int minorTick,
		int majorTick)
	{ 
		JSlider slider = new JSlider();
		slider.setMinimum(min);
		slider.setMaximum(max);
		slider.setMajorTickSpacing(majorTick);
		slider.setMinorTickSpacing(minorTick);
		slider.setPaintTicks(true);
		return slider;
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getComponentOrientation, getOrientation, getPaintLabels, getPaintTicks
        } 
         
        // used to center sliders added using BorderLayout.CENTER (bug 4275631) 
        int centerSpacing = 0;
         
        if (slider.getOrientation() == JSlider.HORIZONTAL) {
            centerSpacing = thumbRect.height;
            if (slider.getPaintTicks()) centerSpacing += getTickLength();
            if (slider.getPaintLabels()) centerSpacing += getHeightOfTallestLabel();
             
            // Determine track position and size.  The track length is equal to 
            // the track image length, minus half of the thumb image length.  
            trackRect.x = contentRect.x + (contentRect.width - 
                (horizontalTrackImage.getWidth() - horizontalThumbImage.getWidth() / 2)) / 2;
            trackRect.y = contentRect.y + (contentRect.height - centerSpacing) / 2;
             
            trackRect.width = horizontalTrackImage.getWidth() - horizontalThumbImage.getWidth() / 2;
            trackRect.height = thumbRect.height;
             
        } else { 

6
CodeRank
This code example shows how to use the following methods:setBorder, setMajorTickSpacing, setMinorTickSpacing, setPaintLabels, setPaintTicks
This code example shows how to use the following methods:getMaximum, getMinimum, getValue
        } 
      
        if (object instanceof JSlider) {
            JSlider slider = (JSlider)object;
             
            return   (double)(slider.getValue()   - slider.getMinimum()) 
                   / (double)(slider.getMaximum() - slider.getMinimum()); 
        } 
         
        throw new IllegalArgumentException(
            "Progress bar painter does not support " + object.getClass().getName()); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setBorder, setMajorTickSpacing, setMinorTickSpacing, setPaintLabels, setPaintTicks
This code example shows how to use the following methods:setUI
     * 
     * @return the HUD style slider. 
     * @see com.explodingpixels.macwidgets.plaf.HudSliderUI 
     */ 
    public static JSlider createHudSlider() {
        JSlider slider = new JSlider();
        slider.setUI(new HudSliderUI(slider));
        return slider;
    } 
} 
5
CodeRank
See Code Examples for Java 8 JSlider Methods: