Java Code Examples for javax.swing.JSlider

The following examples show how to use javax.swing.JSlider. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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 2
Source Project: opencv-fun   Source File: ImgWindow.java    License: 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 3
Source Project: meshnet   Source File: HuslChooserJFrame.java    License: 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 4
Source Project: sc2gears   Source File: GuiUtils.java    License: 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 5
Source Project: pumpernickel   Source File: Inspector.java    License: 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 6
Source Project: marathonv5   Source File: JSliderJavaElementTest.java    License: 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 7
/**
 * 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 8
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 9
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 10
Source Project: littleluck   Source File: LuckSliderUI.java    License: 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 Project: freecol   Source File: PercentageOptionUI.java    License: 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 12
@Override
protected void uninstallListeners(JSlider slider) {
	if (this.thumbPressedListener != null) {
		slider.removeMouseListener(this.thumbPressedListener);
		this.thumbPressedListener = null;
	}
	super.uninstallListeners(slider);
}
 
Example 13
Source Project: stendhal   Source File: SoundSettings.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a volume slider for the master channel.
 *
 * @return master volume slider slider
 */
private JSlider createMasterVolumeSlider() {
	JSlider slider = new JSlider(0, 100);
	float volume = ClientSingletonRepository.getSound().getVolume();
	slider.setValue(Numeric.floatToInt(volume, 100f));
	slider.addChangeListener(new MasterVolumeListener());

	return slider;
}
 
Example 14
Source Project: FlatLaf   Source File: FlatSliderUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void installListeners( JSlider slider ) {
	super.installListeners( slider );

	hoverListener = new FlatUIUtils.HoverListener( slider, h -> {
		hover = h;
	} );
	slider.addMouseListener( hoverListener );
}
 
Example 15
Source Project: PolyGlot   Source File: SoundRecorderTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testSoundRecordingSuite() {
    Assumptions.assumeFalse(GraphicsEnvironment.isHeadless());
    
    System.out.println("SoundRecorderTest.testSoundRecordingSuite");
    
    ImageIcon playButtonUp = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.PLAY_BUTTON_UP)));
    ImageIcon playButtonDown = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.PLAY_BUTTON_DOWN)));
    ImageIcon recordButtonUp = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.RECORD_BUTTON_UP)));
    ImageIcon recordButtonDown = PGTUtil.getButtonSizeIcon(new ImageIcon(getClass().getResource(PGTUtil.RECORD_BUTTON_DOWN)));
    
    try {
        SoundRecorder recorder = new SoundRecorder(null);
        recorder.setButtons(new JButton(), new JButton(), playButtonUp, playButtonDown, recordButtonUp, recordButtonDown);
        recorder.setTimer(new JTextField());
        recorder.setSlider(new JSlider());
        recorder.beginRecording();
        Thread.sleep(1000);
        recorder.endRecording();
        byte[] sound = recorder.getSound();
        recorder.setSound(sound);
        recorder.playPause();
        assertTrue(recorder.isPlaying());
    } catch (Exception e) {
        fail(e);
    } 
}
 
Example 16
Source Project: FlatLaf   Source File: FlatSliderUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void installDefaults( JSlider slider ) {
	super.installDefaults( slider );

	LookAndFeel.installProperty( slider, "opaque", false );

	trackWidth = UIManager.getInt( "Slider.trackWidth" );
	thumbWidth = UIManager.getInt( "Slider.thumbWidth" );

	trackColor = UIManager.getColor( "Slider.trackColor" );
	thumbColor = UIManager.getColor( "Slider.thumbColor" );
	focusColor = FlatUIUtils.getUIColor( "Slider.focusedColor", "Component.focusColor" );
	hoverColor = FlatUIUtils.getUIColor( "Slider.hoverColor", focusColor );
	disabledForeground = UIManager.getColor( "Slider.disabledForeground" );
}
 
Example 17
Source Project: FlatLaf   Source File: FlatSliderUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintThumb( Graphics g ) {
	g.setColor( FlatUIUtils.deriveColor( slider.isEnabled()
		? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor))
		: disabledForeground,
		thumbColor ) );

	if( isRoundThumb() )
		g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height );
	else {
		double w = thumbRect.width;
		double h = thumbRect.height;
		double wh = w / 2;

		Path2D thumb = FlatUIUtils.createPath( 0,0, w,0, w,(h - wh), wh,h,  0,(h - wh) );

		Graphics2D g2 = (Graphics2D) g.create();
		try {
			g2.translate( thumbRect.x, thumbRect.y );
			if( slider.getOrientation() == JSlider.VERTICAL ) {
				if( slider.getComponentOrientation().isLeftToRight() ) {
					g2.translate( 0, thumbRect.height );
					g2.rotate( Math.toRadians( 270 ) );
				} else {
					g2.translate( thumbRect.width, 0 );
					g2.rotate( Math.toRadians( 90 ) );
				}
			}
			g2.fill( thumb );
		} finally {
			g2.dispose();
		}
	}
}
 
Example 18
Source Project: pdfxtk   Source File: StyleEditor.java    License: Apache License 2.0 5 votes vote down vote up
void set(Component c) {
     if(c instanceof Container) {
Component[] cmps = ((Container)c).getComponents();
for(int i = 0; i < cmps.length; i++)
  set(cmps[i]);
     }
     if(c instanceof JLabel) {
if(validHorizontalKey(hAlign))
  ((JLabel)c).setHorizontalAlignment(hAlign);
if(validVerticalKey(vAlign))
  ((JLabel)c).setVerticalAlignment(vAlign);
     }
     if(c instanceof AbstractButton) {
if(validHorizontalKey(hAlign))
  ((AbstractButton)c).setHorizontalAlignment(hAlign);
if(validVerticalKey(vAlign))
  ((AbstractButton)c).setVerticalAlignment(vAlign);
     } 
     if(c instanceof JSlider) {
for(Enumeration e = ((JSlider)c).getLabelTable().elements(); e.hasMoreElements();)
  set((Component)e.nextElement());
c.repaint();
     }
     if(font != null)
c.setFont(font);
     if(foreground != null)
c.setForeground(foreground);
     if(background != null)
c.setBackground(background);
   }
 
Example 19
Source Project: seaglass   Source File: SeaGlassSliderUI.java    License: Apache License 2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    recalculateIfInsetsChanged();
    Dimension d = new Dimension(contentDim);
    if (slider.getOrientation() == JSlider.VERTICAL) {
        d.height = 200;
    } else {
        d.width = 200;
    }
    return d;
}
 
Example 20
Source Project: marathonv5   Source File: RComponentFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static void reset() {
    entries.clear();
    add(Component.class, RUnknownComponent.class);
    add(Window.class, RWindow.class);
    add(JTable.class, RTable.class);
    add(JTableHeader.class, RTableHeader.class);
    add(AbstractButton.class, RAbstractButton.class);
    add(JToggleButton.class, RToggleButton.class);
    add(JComboBox.class, RComboBox.class);
    add(JTextComponent.class, RTextComponent.class);
    add(JTree.class, RTree.class);
    add(JList.class, RList.class);
    add(JTabbedPane.class, RTabbedPane.class);
    add(JMenuItem.class, RMenuItem.class);
    add(JSlider.class, RSlider.class);
    add(JProgressBar.class, RProgressBar.class);
    add(JSpinner.class, RSpinner.class);
    add(DefaultEditor.class, RDefaultEditor.class);
    add(JColorChooser.class, RColorChooser.class);
    add(JSplitPane.class, RSplitPane.class);
    add(BasicSplitPaneDivider.class, RSplitPane.class);
    add(JFileChooser.class, RFileChooser.class);
    add(JEditorPane.class, REditorPane.class);
    add(JLabel.class, RLabel.class);
    add(JScrollBar.class, RIgnoreComponent.class);
    add("com.jidesoft.swing.TristateCheckBox", RJideTristateComponent.class);
    add("com.jidesoft.swing.CheckBoxListCellRenderer", RJideCheckBoxListItem.class);
    add("com.jidesoft.swing.CheckBoxTreeCellRenderer", RJideCheckBoxTreeNode.class);
    add("com.jidesoft.spinner.DateSpinner", RJideDateSpinnerElement.class);
    add("com.jidesoft.swing.JideSplitPane", RJideSplitPaneElement.class);
}
 
Example 21
Source Project: marathonv5   Source File: RSliderTest.java    License: Apache License 2.0 5 votes vote down vote up
public void sliderTest() {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            JSlider slider = (JSlider) ComponentUtils.findComponent(JSlider.class, frame);
            slider.setValue(25);
            RSlider rslider = new RSlider(slider, null, null, lr);
            rslider.focusLost(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("25", call.getState());
}
 
Example 22
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.setModel(BoundedRangeModel)} through queue
 */
public void setModel(final BoundedRangeModel boundedRangeModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JSlider) getSource()).setModel(boundedRangeModel);
        }
    });
}
 
Example 23
Source Project: mars-sim   Source File: ZoomSliderPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
private JSlider getControl() {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 50, 200, 100);
    slider.setMajorTickSpacing(50);
    slider.setMinorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.addChangeListener(this);
    return slider;        
}
 
Example 24
Source Project: Spark   Source File: JavaMixer.java    License: Apache License 2.0 5 votes vote down vote up
private JComponent createControlComponent(FloatControl control) {
    int orientation = isBalanceOrPan(control) ? JSlider.HORIZONTAL : JSlider.VERTICAL;
    BoundedRangeModel model = new JavaMixer.FloatControlBoundedRangeModel(control);
    JSlider slider = new JSlider(model);
    slider.setOrientation(orientation);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setSize(10, 50);
    return slider;
}
 
Example 25
Source Project: Bytecoder   Source File: MotifSliderUI.java    License: 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 );
    }
}
 
Example 26
Source Project: openjdk-8   Source File: CAccessible.java    License: 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 Project: jdk8u_jdk   Source File: CAccessible.java    License: 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 28
Source Project: TencentKona-8   Source File: Test6657026.java    License: 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 29
Source Project: openjdk-8-source   Source File: CAccessible.java    License: 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 Project: magarena   Source File: VolumeSliderPanel.java    License: 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 31
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: 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 32
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: 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 33
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: 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 34
Source Project: megamek   Source File: Slider.java    License: 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 35
Source Project: pumpernickel   Source File: PaddingInfo.java    License: MIT License 5 votes vote down vote up
/**
 * Should be called shortly after <code>prep()</code>.
 */
private static void restore(Component c) {
	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		Boolean b = (Boolean) jc.getClientProperty(USED_TO_BE_OPAQUE);
		if (b != null && b.booleanValue()) {
			jc.setOpaque(true);
		}
		jc.putClientProperty(USED_TO_BE_OPAQUE, null);

		Dimension d = (Dimension) jc.getClientProperty(SIZE);
		if (d != null) {
			jc.setSize(d);
			jc.putClientProperty(SIZE, null);
		}
	}
	if (c instanceof JSlider) {
		JSlider s = (JSlider) c;
		ChangeListener[] listeners = (ChangeListener[]) s
				.getClientProperty(CHANGE_LISTENERS);
		Integer i = (Integer) s.getClientProperty(SLIDER_VALUE);
		if (i != null)
			s.setValue(i.intValue());
		if (listeners != null) {
			for (int a = 0; a < listeners.length; a++) {
				s.addChangeListener(listeners[a]);
			}
		}
		s.putClientProperty(SLIDER_VALUE, null);
		s.putClientProperty(CHANGE_LISTENERS, null);
	}
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			restore(c2.getComponent(a));
		}
	}
}
 
Example 36
Source Project: zxpoly   Source File: PenWidth.java    License: 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 37
Source Project: jdk8u60   Source File: Test6657026.java    License: 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 38
Source Project: jason   Source File: Calendar.java    License: 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 39
Source Project: pumpernickel   Source File: AngleSliderUI.java    License: MIT License 5 votes vote down vote up
@Override
public void uninstallUI(JComponent c) {
	JSlider slider = (JSlider) c;
	slider.removeFocusListener(focusListener);
	slider.removeMouseListener(mouseListener);
	slider.removeMouseMotionListener(mouseListener);
	RepaintChangeListener rcl = (RepaintChangeListener) slider
			.getClientProperty(REPAINT_CHANGE_LISTENER_KEY);
	slider.getModel().removeChangeListener(rcl);
	slider.removeKeyListener(keyListener);
}
 
Example 40
Source Project: nanoleaf-desktop   Source File: ModernSliderUI.java    License: 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);
}