Java Code Examples for javax.swing.JSlider#setModel()

The following examples show how to use javax.swing.JSlider#setModel() . 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: RangeOptionUI.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code RangeOptionUI} for the given
 * {@code RangeOption}.
 *
 * @param option The {@code RangeOption} to make a user interface for
 * @param editable boolean whether user can modify the setting
 */
public RangeOptionUI(final RangeOption option, boolean editable) {
    super(option, editable);

    JSlider slider = getComponent();

    slider.setModel(new DefaultBoundedRangeModel(option.getValueRank(), 0,
            0, option.getItemValues().size()-1));

    Hashtable<Integer, JComponent> labels
        = new Hashtable<>();
    int index = 0;
    for (String string : option.getItemValues().values()) {
        if (option.localizeLabels()) {
            labels.put(index, Utility.localizedLabel(string));
        } else {
            labels.put(index, new JLabel(string));
        }
        index++;
    }

    slider.setLabelTable(labels);
    slider.setValue(option.getValueRank());
    slider.setMajorTickSpacing(1);
    slider.setSnapToTicks(true);
}
 
Example 2
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 3
Source File: JComponentBuilders.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setupInstance(JSlider instance) {
    super.setupInstance(instance);
    
    instance.setPaintTicks(paintTicks);
    instance.setPaintTrack(paintTrack);
    instance.setPaintLabels(paintLabels);
    instance.setInverted(isInverted);
    if (sliderModel != null) instance.setModel(sliderModel.createInstance());
    instance.setMajorTickSpacing(majorTickSpacing);
    instance.setMinorTickSpacing(minorTickSpacing);
    instance.setSnapToTicks(snapToTicks);
}
 
Example 4
Source File: JComponentBuilders.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
protected void setupInstance(JSlider instance) {
    super.setupInstance(instance);
    
    instance.setPaintTicks(paintTicks);
    instance.setPaintTrack(paintTrack);
    instance.setPaintLabels(paintLabels);
    instance.setInverted(isInverted);
    if (sliderModel != null) instance.setModel(sliderModel.createInstance());
    instance.setMajorTickSpacing(majorTickSpacing);
    instance.setMinorTickSpacing(minorTickSpacing);
    instance.setSnapToTicks(snapToTicks);
}
 
Example 5
Source File: LoadSpeedSimulationPanel.java    From blog with Apache License 2.0 5 votes vote down vote up
public LoadSpeedSimulationPanel() {
	setLayout(null);
	loadPersonsSpeedModel.setMinimum(0);
	loadPersonsSpeedModel.setMaximum(MAX_LOAD_SPEED_MS);
	loadPersonsSpeedModel.setValue(INITIAL_LOAD_SPEED_MS);
	loadPersonsSpeedModel.setExtent(0);

	JSlider loadSpeedSlider = new JSlider();
	loadSpeedSlider.setMinorTickSpacing(MIN_LOAD_SPEED_TICK_MS);
	loadSpeedSlider.setSnapToTicks(true);
	loadSpeedSlider.setPaintTicks(true);
	loadSpeedSlider.setPaintLabels(true);
	loadSpeedSlider.setBounds(161, 12, 429, 43);
	loadSpeedSlider.setModel(loadPersonsSpeedModel);
	add(loadSpeedSlider);

	JLabelTextComponent selectedLoadSpeed = new JLabelTextComponent("");
	selectedLoadSpeed.setFont(new Font("Tahoma", Font.PLAIN, 12));
	selectedLoadSpeed.setBounds(10, 38, 138, 14);
	add(selectedLoadSpeed);

	// adapt the jLabel to the Document model to support MVC.

	MessageFormat speedLabelFormat = new MessageFormat(
			SIMULATION_SPEED_FORMAT);
	Document loadSpeedDocument = selectedLoadSpeed.getDocument();
	BoundedRangeModel2DocumentAdapter boundedRangeAdapter = new BoundedRangeModel2DocumentAdapter(
			loadSpeedDocument, speedLabelFormat);
	boundedRangeAdapter.bind(loadPersonsSpeedModel);

	JLabel label = new JLabel("Load Speed Simulation");
	label.setFont(new Font("Tahoma", Font.PLAIN, 12));
	label.setBounds(10, 11, 138, 14);
	add(label);

	setPreferredSize(new Dimension(600, 60));
}
 
Example 6
Source File: PropertySliderValueBinding.java    From pgptool with GNU General Public License v3.0 4 votes vote down vote up
public PropertySliderValueBinding(ModelSliderPropertyAccessor property, JSlider slider) {
	this.property = property;
	this.slider = slider;

	slider.setModel(property.getBoundedRangeModel());
}