当前位置: 首页>>代码示例>>Java>>正文


Java JSlider.setSnapToTicks方法代码示例

本文整理汇总了Java中javax.swing.JSlider.setSnapToTicks方法的典型用法代码示例。如果您正苦于以下问题:Java JSlider.setSnapToTicks方法的具体用法?Java JSlider.setSnapToTicks怎么用?Java JSlider.setSnapToTicks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JSlider的用法示例。


在下文中一共展示了JSlider.setSnapToTicks方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RangeOptionUI

import javax.swing.JSlider; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:33,代码来源:RangeOptionUI.java

示例2: PercentageOptionUI

import javax.swing.JSlider; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:27,代码来源:PercentageOptionUI.java

示例3: setupInstance

import javax.swing.JSlider; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:JComponentBuilders.java

示例4: getAnimationPanel

import javax.swing.JSlider; //导入方法依赖的package包/类
/**
 * Returns the frames-per-second slider for the animation dialog.
 */
final JPanel getAnimationPanel() {
    // lazily create the label
    if (this.animationPanel == null) {
        JLabel label = new JLabel("Animation Speed");
        label.setAlignmentX(Component.CENTER_ALIGNMENT);
        final JSlider slider = new JSlider(SwingConstants.HORIZONTAL, 1, 10, 2) {
            @Override
            public void updateUI() {
                setUI(BasicSliderUI.createUI(this));
            }
        };
        slider.setMajorTickSpacing(9);
        slider.setMinorTickSpacing(1);
        slider.setSnapToTicks(true);
        slider.setPaintTicks(true);
        slider.setPaintLabels(true);
        slider.setFocusable(false);
        slider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                int speed = slider.getValue();
                setSpeed(speed);
            }
        });
        slider.setAlignmentX(Component.CENTER_ALIGNMENT);
        this.animationPanel = new JPanel();
        this.animationPanel.setLayout(new BoxLayout(this.animationPanel, BoxLayout.Y_AXIS));
        this.animationPanel.add(label);
        this.animationPanel.add(slider);
    }
    return this.animationPanel;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:36,代码来源:ExploreAction.java

示例5: editProfile

import javax.swing.JSlider; //导入方法依赖的package包/类
public FanSpeedProfile editProfile(FanSpeedProfile profile) {
	JPanel panel = new JPanel(), sliderPanel = new JPanel(), weightPanel = new JPanel();
	JSlider[] sliders;
	JSlider weightSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
	JTextField nameField = new JTextField(20);
	if (profile != null) {
		nameField.setText(profile.getName());
		sliders = Arrays.stream(profile.getPercentages()).mapToObj(i -> new JSlider(JSlider.VERTICAL, 0, 100, i))
				.toArray(JSlider[]::new);
		weightSlider.setValue(profile.getCpuWeight());
	} else {
		sliders = IntStream.range(0, FanSpeedProfile.STEPS).mapToObj(i -> new JSlider(JSlider.VERTICAL, 0, 100, 50))
				.toArray(JSlider[]::new);
	}
	
	sliderPanel.setLayout(new GridLayout(1, sliders.length));
	
	sliders[sliders.length -1].setPaintLabels(true);

	for (int i = 0; i < sliders.length; i++) {
		JSlider s = sliders[i];
		s.setPaintTicks(true);
		s.setSnapToTicks(true);
		s.setLabelTable(dictionary);
		s.setMinorTickSpacing(5);
		s.setMajorTickSpacing(50);
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
		p.add(s);
		p.add(new JLabel(FanSpeedProfile.MIN_TEMP + FanSpeedProfile.STEP_SIZE * i + " \u00B0C"));
		sliderPanel.add(p);
	}

	panel.setLayout(new BorderLayout());
	panel.add(GridControlPanel.labelledComponent("Profile name: ", nameField), BorderLayout.NORTH);

	panel.add(sliderPanel, BorderLayout.CENTER);
	
	weightPanel.add(new JLabel("GPU"));
	weightSlider.setMajorTickSpacing(50);
	weightSlider.setMinorTickSpacing(10);
	weightSlider.setPaintTicks(true);
	weightPanel.add(weightSlider);
	weightPanel.add(new JLabel("CPU"));
	panel.add(weightPanel, BorderLayout.SOUTH);

	int response = JOptionPane.showConfirmDialog(null, panel, "Fan Speed Profile Editor",
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

	if (response == JOptionPane.OK_OPTION) {
		int[] percs = Arrays.stream(sliders).mapToInt(JSlider::getValue).toArray();
		if (profile == null)
			profile = new FanSpeedProfile(nameField.getText(), percs, weightSlider.getValue());
		else {
			profile.setPercentages(percs);
			profile.setName(nameField.getText());
			profile.setCpuWeight(weightSlider.getValue());
		}
		if (nameField.getText().isEmpty()) {
			JOptionPane.showMessageDialog(null, "Please enter a name for the profile.");
			return editProfile(profile);
		}
		return profile;
	} else {
		return profile;
	}
}
 
开发者ID:Tankernn,项目名称:JavaGridControl,代码行数:68,代码来源:ProfileEditor.java


注:本文中的javax.swing.JSlider.setSnapToTicks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。