javax.swing.JSlider Java Examples

The following examples show how to use javax.swing.JSlider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimulateControlPanel.java    From VanetSim with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Creates a slider for zooming.
 * 
 * @return a ready-to-use <code>JSlider</code>
 */
private JSlider getZoomSlider() {
	JSlider slider = new JSlider(-75, 212, 1);
	Hashtable<Integer,JLabel> ht = new Hashtable<Integer,JLabel>();
	// the labels correspond to a exponential scale but internally the slider calculates only in a constant scale => need to convert in stateChanged()!
	ht.put(-75, new JLabel("3km"));	//$NON-NLS-1$
	ht.put(-20, new JLabel("1km"));	//$NON-NLS-1$
	ht.put(45, new JLabel("200m"));	//$NON-NLS-1$
	ht.put(96, new JLabel("100m"));	//$NON-NLS-1$
	ht.put(157, new JLabel("30m"));	//$NON-NLS-1$
	ht.put(212, new JLabel("10m"));	//$NON-NLS-1$
	slider.setLabelTable(ht);
	slider.setPaintLabels(true);
	slider.setMinorTickSpacing(10);
	slider.setMajorTickSpacing(40);
	//slider.setPaintTicks(true);
	slider.addChangeListener(this);
	return slider;
}
 
Example #2
Source File: TrackingPong.java    From marvinproject with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadGUI(){	
	setTitle("Video Sample - Tracking Pong");
	
	videoPanel.addMouseListener(new MouseHandler());
	
	sliderSensibility = new JSlider(JSlider.HORIZONTAL, 0, 60, 30);
	sliderSensibility.setMinorTickSpacing(2);
	sliderSensibility.setPaintTicks(true);
	sliderSensibility.addChangeListener(new SliderHandler());
	
	labelSlider = new JLabel("Sensibility");
	
	panelSlider = new JPanel();
	panelSlider.add(labelSlider);
	panelSlider.add(sliderSensibility);
	
	Container container = getContentPane();
	container.setLayout(new BorderLayout());
	container.add(videoPanel, BorderLayout.NORTH);
	container.add(panelSlider, BorderLayout.SOUTH);
	
	setSize(videoInterface.getImageWidth()+20,videoInterface.getImageHeight()+100);
	setVisible(true);
}
 
Example #3
Source File: GenericView.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * associate a model with this view
 */
public void setModel(Model aModel) {
    model = (GenericModel) aModel;
    for (final Variable v:model.getVariables()) {
        JPanel p=new JPanel();
        p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
        JLabel lab=new JLabel(v.getName());
        final JSlider slider=new JSlider(0,1000);
        p.add(lab);
        p.add(slider);
        final double maxv=v.getUniverseMax();
        final double minv=v.getUniverseMin();
        
        slider.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                double x=minv+(slider.getModel().getValue())*(maxv-minv)/1000.0;
                v.setValue(x);
            }
        });
       add(p); 
        
       System.out.println(" Added " + v.getName());
    }
    validate();
    repaint();
}
 
Example #4
Source File: DetectMotionRegions.java    From marvinproject with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadGUI(){
	setTitle("Video Sample - Detect Motion Regions");
	
	sliderSensibility = new JSlider(JSlider.HORIZONTAL, 0, 60, 30);
	sliderSensibility.setMinorTickSpacing(2);
	sliderSensibility.setPaintTicks(true);
	sliderSensibility.addChangeListener(new SliderHandler());
	
	labelSlider = new JLabel("Sensibility");
	
	panelSlider = new JPanel();
	panelSlider.add(labelSlider);
	panelSlider.add(sliderSensibility);
	
	Container container = getContentPane();
	container.setLayout(new BorderLayout());
	container.add(videoPanel, BorderLayout.NORTH);
	container.add(panelSlider, BorderLayout.SOUTH);
	
	setSize(imageWidth+10,imageHeight+100);
	setVisible(true);	
}
 
Example #5
Source File: ImgWindow.java    From opencv-fun with GNU Affero General Public License v3.0 6 votes vote down vote up
public void addSlider(final int min, final int max, final int initial, final ValueCallback callback) {
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run () {
				JPanel panel = ImgWindow.this;
				final JSlider slider = new JSlider(min, max, initial);
				slider.addChangeListener(new ChangeListener() {
					@Override
					public void stateChanged (ChangeEvent e) {
//						if(!slider.getValueIsAdjusting()) {
							eventQueue.add(new Runnable() {
								@Override
								public void run () {
									if(callback != null) callback.valueChanged(slider.getValue());
								}
							});
//						}
					}
				});			
				panel.add(slider);
				panel.validate();
			}
		});
	}
 
Example #6
Source File: Inspector.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Process new components. This may change opacity, borders, or other
 * properties. This method should only be called once per component, and it
 * should be called before {@link #getInsets(Position, JComponent)}.
 * 
 * @param position
 *            the position of this JComponent.
 * @param component
 *            the component to prepare for installation.
 */
protected void prepare(Position position, JComponent component) {
	if (component instanceof JSlider || component instanceof JRadioButton
			|| component instanceof JCheckBox)
		component.setOpaque(false);

	if (component instanceof JCheckBox || component instanceof JLabel
			|| component instanceof JRadioButton
			|| component instanceof JSlider) {
		component.setBorder(null);
	}

	if (component instanceof JCheckBox || component instanceof JRadioButton) {
		AbstractButton b = (AbstractButton) component;
		prepareButton(b);
	}
}
 
Example #7
Source File: JSliderJavaElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    JavaElementFactory.add(JSlider.class, JSliderJavaElement.class);
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(JSliderJavaElementTest.class.getSimpleName());
            frame.setName("frame-" + JSliderJavaElementTest.class.getSimpleName());
            frame.getContentPane().add(new SliderDemo(), BorderLayout.CENTER);
            frame.pack();
            frame.setAlwaysOnTop(true);
            frame.setVisible(true);
        }
    });
    driver = new JavaAgent();
}
 
Example #8
Source File: HuslChooserJFrame.java    From meshnet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create the frame.
 */
public HuslChooserJFrame(CieXYZColorSelectedListener clickedListener) {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setBounds(100, 100, 450, 300);
	contentPane = new HuslChooserJPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	contentPane.setLayout(new BorderLayout(0, 0));
	setContentPane(contentPane);
	
	this.clickedListener = clickedListener;
	
	final JSlider slider = new JSlider(0, 100, 0);
	slider.addChangeListener(new ChangeListener() {
		public void stateChanged(ChangeEvent e) {
			l = slider.getValue();
			contentPane.drawColorChooser();
			contentPane.repaint();
			updateLedColor();
		}
	});
	
	getContentPane().add(slider, BorderLayout.NORTH);
}
 
Example #9
Source File: PercentageOptionUI.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code PercentageOptionUI} for the given
 * {@code PercentageOption}.
 *
 * @param option The {@code PercentageOption} to make a user
 *     interface for.
 * @param editable boolean whether user can modify the setting
 */
public PercentageOptionUI(final PercentageOption option, boolean editable) {
    super(option, editable);

    JSlider slider = getComponent();

    slider.setModel(new DefaultBoundedRangeModel(option.getValue(), 0, 0, 100));
    Hashtable<Integer, JComponent> labels
        = new Hashtable<>();
    labels.put(0,   new JLabel("0 %"));
    labels.put(25,  new JLabel("25 %"));
    labels.put(50,  new JLabel("50 %"));
    labels.put(75,  new JLabel("75 %"));
    labels.put(100, new JLabel("100 %"));
    slider.setLabelTable(labels);
    slider.setValue(option.getValue());
    slider.setMajorTickSpacing(5);
    slider.setSnapToTicks(false);
}
 
Example #10
Source File: LuckSliderUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public void paintThumb(Graphics g)
{
    // 如果还未初始化图片资源,则先初始化。
    // The initialization of the resources required.
    initRes(slider.getOrientation());

    Rectangle knobBounds = thumbRect;

    g.translate(knobBounds.x, knobBounds.y);

    if (slider.getOrientation() == JSlider.HORIZONTAL)
    {
        g.drawImage(horizontaltThumbImg, 0, 0, null);
    }
    else
    {
        g.drawImage(verticalThumbImg, 0, 0, null);
    }

    g.translate(-knobBounds.x, -knobBounds.y);
}
 
Example #11
Source File: GuiUtils.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a slider whose value is bound to the specified settingKey.<br>
 * The initial value of the slider will be taken from the {@link Settings},
 * and a change listener will be added to the slider to register changes at the {@link Settings}.<br>
 * 
 * @param settingKey key of the setting its value is bound to
 * @param minValue   the minimum value
 * @param maxValue   the maximum value
 * @return the created slider
 */
public static JSlider createSlider( final String settingKey, final int minValue, final int maxValue ) {
	final JSlider slider = new JSlider( minValue, maxValue, Settings.getInt( settingKey ) );
	
	slider.addChangeListener( new ChangeListener() {
		@Override
		public void stateChanged( final ChangeEvent event ) {
			if ( slider.getValueIsAdjusting() )
				return;
			
			Settings.set( settingKey, slider.getValue() );
		}
	} );
	
	return slider;
}
 
Example #12
Source File: MovieContainer.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
/**
 * adds the toolbar at the bottom
 */
private void addPlayUI() {
	// Add the bottom menu bar
	movieToolbar = new JToolBar();
	
	fileButton = makeToolButton("", "choose_simulation_file", "Choose Simulation", this);
	movieToolbar.add(fileButton);
	
	clearButton = makeToolButton("", "clearAppearances", "Clear Appearances", this);
	movieToolbar.add(clearButton);
	
	movieToolbar.addSeparator();
	
	rewindButton = makeToolButton("movie" + File.separator + "rewind.png", "rewind", "Rewind", this);
	movieToolbar.add(rewindButton);

	singleStepButton = makeToolButton("movie" + File.separator + "single_step.png", "singlestep", "Single Step", this);
	movieToolbar.add(singleStepButton);
	
	playPauseButton = makeToolButton("movie" + File.separator + "play.png", "playpause", "Play", this);
	movieToolbar.add(playPauseButton);
		
	slider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0);
	slider.setSnapToTicks(true);
	movieToolbar.add(slider);
	
	movieToolbar.setFloatable(false);

	this.add(movieToolbar, BorderLayout.SOUTH);
}
 
Example #13
Source File: ModernSliderUI.java    From nanoleaf-desktop with MIT License 5 votes vote down vote up
public ModernSliderUI(JSlider b)
{
	super(b);
	thumbColor = Color.GRAY;
	UIManager.put("Slider.shadow", Color.DARK_GRAY);
	UIManager.put("Slider.highlight", Color.DARK_GRAY);
}
 
Example #14
Source File: JSliderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.getModel()} through queue
 */
public BoundedRangeModel getModel() {
    return (runMapping(new MapAction<BoundedRangeModel>("getModel") {
        @Override
        public BoundedRangeModel map() {
            return ((JSlider) getSource()).getModel();
        }
    }));
}
 
Example #15
Source File: MotifSliderUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected Dimension getThumbSize() {
    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        return new Dimension( 30, 15 );
    }
    else {
        return new Dimension( 15, 30 );
    }
}
 
Example #16
Source File: JSliderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.setLabelTable(Dictionary)} through queue
 */
public void setLabelTable(final Dictionary<?, ?> dictionary) {
    runMapping(new MapVoidAction("setLabelTable") {
        @Override
        public void map() {
            ((JSlider) getSource()).setLabelTable(dictionary);
        }
    });
}
 
Example #17
Source File: JSliderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.getOrientation()} through queue
 */
public int getOrientation() {
    return (runMapping(new MapIntegerAction("getOrientation") {
        @Override
        public int map() {
            return ((JSlider) getSource()).getOrientation();
        }
    }));
}
 
Example #18
Source File: JSliderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.getMajorTickSpacing()} through queue
 */
public int getMajorTickSpacing() {
    return (runMapping(new MapIntegerAction("getMajorTickSpacing") {
        @Override
        public int map() {
            return ((JSlider) getSource()).getMajorTickSpacing();
        }
    }));
}
 
Example #19
Source File: Calendar.java    From jason with GNU Lesser General Public License v3.0 5 votes vote down vote up
@INTERNAL_OPERATION
void updateDay(ChangeEvent ev) {
    JSlider source = (JSlider) ev.getSource();
    if (!source.getValueIsAdjusting()) {
        try {
            ObsProperty prop = getObsProperty("today");
            prop.updateValue(days[(int) s.getValue()]);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
}
 
Example #20
Source File: VolumeSliderPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public VolumeSliderPanel(int initialValue, MagicSound aSound) {

        slider = new JSlider(0, 100, initialValue);
        slider.setFocusable(false);
        slider.addChangeListener((event) -> {
            if (!slider.getValueIsAdjusting()) {
                aSound.play(slider.getValue());
            }
        });

        setLayout(new MigLayout());
        add(new JLabel("Off"));
        add(slider, "w 100%");
        add(new JLabel("100%"));
    }
 
Example #21
Source File: Test6657026.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(JSlider slider) {
    MetalSliderUI ui = (MetalSliderUI) slider.getUI();
    int actual = ui.getTickLength();
    if (actual != 11) {
        throw new Error(actual + ", but expected 11");
    }
}
 
Example #22
Source File: Slider.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public Slider(JFrame parent, String title, String question,
        int defaultValue, int min, int max) {
    super(parent, title, true);
    super.setResizable(false);

    value = new JSlider(SwingConstants.HORIZONTAL, min, max, defaultValue);
    value.addChangeListener(this);

    getContentPane().setLayout(new BorderLayout());
    JPanel qp = new JPanel();
    qp.setLayout(new BorderLayout());
    lblText.setText(question);
    qp.add(lblText, BorderLayout.NORTH);
    getContentPane().add(qp, BorderLayout.NORTH);

    JPanel sp1 = new JPanel();
    sp1.setLayout(new FlowLayout());
    minText.setText(String.valueOf(min));
    maxText.setText(String.valueOf(max));
    curText.setText(String.valueOf(defaultValue));
    sp1.add(minText);
    sp1.add(value);
    sp1.add(maxText);
    sp1.add(curText);
    getContentPane().add(sp1, BorderLayout.CENTER);

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    butOk.addActionListener(this);
    p.add(butOk);
    butCancel.addActionListener(this);
    p.add(butCancel);
    getContentPane().add(p, BorderLayout.SOUTH);
    pack();
    setLocation(parent.getLocation().x + parent.getSize().width / 2
            - getSize().width / 2, parent.getLocation().y
            + parent.getSize().height / 2 - getSize().height / 2);
}
 
Example #23
Source File: JSliderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.setInverted(boolean)} through queue
 */
public void setInverted(final boolean b) {
    runMapping(new MapVoidAction("setInverted") {
        @Override
        public void map() {
            ((JSlider) getSource()).setInverted(b);
        }
    });
}
 
Example #24
Source File: PenWidth.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
public PenWidth() {
  super();
  this.changeListener =
      (ChangeEvent e) -> drawImageForValue(((BoundedRangeModel) e.getSource()).getValue());
  setOpaque(false);
  setLayout(new BorderLayout(0, 0));

  this.showImage = new BufferedImage(ICON_WIDTH, ICON_HEIGHT, BufferedImage.TYPE_INT_RGB);

  this.widthSlider = new JSlider();
  this.widthSlider.setMajorTickSpacing(10);
  this.widthSlider.setMinorTickSpacing(5);
  this.widthSlider.setSnapToTicks(false);

  this.showLabel = new JLabel(new ImageIcon(showImage));

  add(this.showLabel, BorderLayout.CENTER);
  add(this.widthSlider, BorderLayout.SOUTH);

  this.widthSlider.setSize(ICON_WIDTH << 1, 10);
  this.widthSlider.setFocusable(false);

  setBorder(this.titledBorder);

  setSize(getPreferredSize());

  updateLookForCurrentModel();
}
 
Example #25
Source File: JSliderOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.getPaintTicks()} through queue
 */
public boolean getPaintTicks() {
    return (runMapping(new MapBooleanAction("getPaintTicks") {
        @Override
        public boolean map() {
            return ((JSlider) getSource()).getPaintTicks();
        }
    }));
}
 
Example #26
Source File: CAccessible.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListeners(Component c) {
    if (c instanceof JTextComponent) {
        JTextComponent tc = (JTextComponent) c;
        AXTextChangeNotifier listener = new AXTextChangeNotifier();
        tc.getDocument().addDocumentListener(listener);
        tc.addCaretListener(listener);
    }
    if (c instanceof JProgressBar) {
        JProgressBar pb = (JProgressBar) c;
        pb.addChangeListener(new AXProgressChangeNotifier());
    } else if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        slider.addChangeListener(new AXProgressChangeNotifier());
    }
}
 
Example #27
Source File: Test6657026.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(JSlider slider) {
    MetalSliderUI ui = (MetalSliderUI) slider.getUI();
    int actual = ui.getTickLength();
    if (actual != 11) {
        throw new Error(actual + ", but expected 11");
    }
}
 
Example #28
Source File: CAccessible.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListeners(Component c) {
    if (c instanceof Accessible) {
        AccessibleContext ac = ((Accessible)c).getAccessibleContext();
        ac.addPropertyChangeListener(new AXChangeNotifier());
    }
    if (c instanceof JProgressBar) {
        JProgressBar pb = (JProgressBar) c;
        pb.addChangeListener(new AXProgressChangeNotifier());
    } else if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        slider.addChangeListener(new AXProgressChangeNotifier());
    }
}
 
Example #29
Source File: CAccessible.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListeners(Component c) {
    if (c instanceof JTextComponent) {
        JTextComponent tc = (JTextComponent) c;
        AXTextChangeNotifier listener = new AXTextChangeNotifier();
        tc.getDocument().addDocumentListener(listener);
        tc.addCaretListener(listener);
    }
    if (c instanceof JProgressBar) {
        JProgressBar pb = (JProgressBar) c;
        pb.addChangeListener(new AXProgressChangeNotifier());
    } else if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        slider.addChangeListener(new AXProgressChangeNotifier());
    }
}
 
Example #30
Source File: MotifSliderUI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
protected Dimension getThumbSize() {
    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        return new Dimension( 30, 15 );
    }
    else {
        return new Dimension( 15, 30 );
    }
}