本文整理汇总了Java中javax.swing.JSlider.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java JSlider.setValue方法的具体用法?Java JSlider.setValue怎么用?Java JSlider.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JSlider
的用法示例。
在下文中一共展示了JSlider.setValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSlider
import javax.swing.JSlider; //导入方法依赖的package包/类
/** Set the position of an item that has been added using
* addSlider. Notify listeners that the value has changed.
* @param name The name of the entry.
* @param value The value to set the slider position.
* @exception NoSuchElementException If there is no item with the
* specified name. Note that this is a runtime exception, so it
* need not be declared explicitly.
* @exception IllegalArgumentException If the entry is not a
* slider. This is a runtime exception, so it
* need not be declared explicitly.
*/
public void setSlider(String name, int value) {
Object result = _entries.get(name);
if (result == null) {
throw new NoSuchElementException(
"No item named \"" + name + " \" in the query box.");
}
if (result instanceof JSlider) {
JSlider theSlider = (JSlider) result;
// Set the new slider position.
theSlider.setValue(value);
} else {
throw new IllegalArgumentException(
"Item named \""
+ name
+ "\" is not a slider, and hence cannot be set using "
+ "setSlider().");
}
_notifyListeners(name);
}
示例2: 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);
}
示例3: 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);
}
示例4: setParseTreeViewer
import javax.swing.JSlider; //导入方法依赖的package包/类
public void setParseTreeViewer(TreeViewer aParseTree) {
parseTreeViewer = aParseTree;
JSlider scaleSlider = new JSlider();
scaleSlider.setMinimum(PARSE_TREE_MIN_VAL);
scaleSlider.setMaximum(PARSE_TREE_MAX_VAL);
// JSlider only has integer values
scaleSlider.setValue((int) (PARSE_TREE_DEFAULT_SCALE / PARSE_TREE_SLIDER_FACTOR));
aParseTree.setScale(PARSE_TREE_DEFAULT_SCALE);
JScrollPane parseTreeSP = new JScrollPane(aParseTree);
parseTreeSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
parseTreeSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
getParseTreePanel().removeAll();
getParseTreePanel().add(parseTreeSP, BorderLayout.CENTER);
getParseTreePanel().add(scaleSlider, BorderLayout.SOUTH);
scaleSlider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
double scaleValue =
((double) scaleSlider.getValue()) * PARSE_TREE_SLIDER_FACTOR;
aParseTree.setScale(scaleValue);
}
});
}
示例5: createFilterPanel
import javax.swing.JSlider; //导入方法依赖的package包/类
/**
* @return
*/
private Component createFilterPanel() {
JPanel jp = new MyJPanel("Filter nodes", Color.RED);
jp.add(new JLabel("Betweenness:"));
mNodeAcceptBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
mNodeAcceptBetweennessSlider.setPreferredSize(new Dimension(180, 40));
mNodeAcceptBetweennessSlider.setValue(0);
mNodeAcceptBetweennessSlider.setPaintTicks(true);
mNodeAcceptBetweennessSlider.setBackground(Color.WHITE);
jp.add(mNodeAcceptBetweennessSlider);
return jp;
}
示例6: 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;
}
}
示例7: createSizePanel
import javax.swing.JSlider; //导入方法依赖的package包/类
/**
* @return
*/
private Component createSizePanel() {
final ButtonGroup buttons = new ButtonGroup();
JPanel jp = new MyJPanel("Node Size", Color.RED);
mNodeSizeDegreeSlider = new JSlider(JSlider.HORIZONTAL);
mNodeSizeDegreeSlider.setPreferredSize(new Dimension(180, 40));
mNodeSizeDegreeSlider.setPaintTicks(true);
mNodeSizeDegreeSlider.setBackground(Color.WHITE);
mNodeSizeDegreeSlider.setValue(0);
final JRadioButton degree = new JRadioButton("Degree");
degree.setBackground(Color.WHITE);
degree.setSelected(true);
buttons.add(degree);
jp.add( degree );
jp.add(mNodeSizeDegreeSlider);
mNodeSizePageRankSlider = new JSlider(JSlider.HORIZONTAL);
mNodeSizePageRankSlider.setPreferredSize(new Dimension(180, 40));
mNodeSizePageRankSlider.setPaintTicks(true);
mNodeSizePageRankSlider.setBackground(Color.WHITE);
mNodeSizePageRankSlider.setEnabled( false );
final JRadioButton rank = new JRadioButton("PageRank with Prior");
rank.setBackground(Color.WHITE);
buttons.add(rank);
jp.add( rank );
jp.add( mNodeSizePageRankSlider);
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if( e.getSource() == rank) {
mNodeSizePageRankSlider.setEnabled(true);
mNodeSizeDegreeSlider.setEnabled(false);
}
if ( e.getSource() == degree) {
mNodeSizePageRankSlider.setEnabled(false);
mNodeSizeDegreeSlider.setEnabled(true);
}
}
};
degree.addActionListener(al);
rank.addActionListener(al);
return jp;
}