本文整理汇总了Java中javax.swing.JSlider类的典型用法代码示例。如果您正苦于以下问题:Java JSlider类的具体用法?Java JSlider怎么用?Java JSlider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSlider类属于javax.swing包,在下文中一共展示了JSlider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buidSlider
import javax.swing.JSlider; //导入依赖的package包/类
/**
* Creates the image slider component
*
* @return JComponent
*/
private JComponent buidSlider() {
slider = new JSlider(0, 0);
slider.setPreferredSize(new Dimension(120, 25));
slider.setEnabled(false);
slider.setOpaque(false);
slider.setFocusable(false);
slider.addChangeListener((ChangeEvent e) -> {
if (input != null) {
if (input instanceof MultiFileInput) {
MultiFileInput multi = (MultiFileInput) input;
input = new MultiFileInput(multi.getFiles(), slider.getValue());
fireValueChanged();
}
}
});
return slider;
}
示例2: getBindingDescriptors
import javax.swing.JSlider; //导入依赖的package包/类
@Override
public List<BindingDescriptor>[] getBindingDescriptors(RADComponent component) {
BeanDescriptor beanDescriptor = component.getBeanInfo().getBeanDescriptor();
List<BindingDescriptor>[] descs = getBindingDescriptors(null, beanDescriptor, false);
Class<?> beanClass = component.getBeanClass();
if (JTextComponent.class.isAssignableFrom(beanClass)) {
// get rid of text_... descriptors
descs[0] = filterDescriptors(descs[0], "text_"); // NOI18N
} else if (JTable.class.isAssignableFrom(beanClass)
|| JList.class.isAssignableFrom(beanClass)
|| JComboBox.class.isAssignableFrom(beanClass)) {
// get rid of selectedElement(s)_... descriptors
descs[0] = filterDescriptors(descs[0], "selectedElement_"); // NOI18N
descs[0] = filterDescriptors(descs[0], "selectedElements_"); // NOI18N
// add elements descriptor
BindingDescriptor desc = new BindingDescriptor("elements", List.class); // NOI18N
descs[0].add(0, desc);
} else if (JSlider.class.isAssignableFrom(beanClass)) {
// get rid of value_... descriptor
descs[0] = filterDescriptors(descs[0], "value_"); // NOI18N
}
return descs;
}
示例3: enableSliderToolTips
import javax.swing.JSlider; //导入依赖的package包/类
public static void enableSliderToolTips(final JSlider slider) {
slider.addChangeListener(new ChangeListener() {
private boolean adjusting = false;
private String oldTooltip;
@Override
public void stateChanged(ChangeEvent e) {
if (slider.getModel().getValueIsAdjusting()) {
if (!adjusting) {
oldTooltip = slider.getToolTipText();
adjusting = true;
}
slider.setToolTipText(String.valueOf(slider.getValue()));
hideToolTip(slider);
postToolTip(slider);
} else {
hideToolTip(slider);
slider.setToolTipText(oldTooltip);
adjusting = false;
oldTooltip = null;
}
}
});
}
示例4: 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);
}
示例5: addSliderListener
import javax.swing.JSlider; //导入依赖的package包/类
private void addSliderListener()
{
m_slideProbability.addChangeListener(new ChangeListener()
{
@Override
public void stateChanged(ChangeEvent e)
{
int value = ((JSlider) e.getSource()).getValue();
String curProc = m_lstProcNames.getSelectedValue().toString();
try
{
ProcEnv.setProbability(curProc, value);
m_txtProbability.setText(Integer.toString(value));
}
catch (TotalProbabilityExceeds100Exception e1)
{
Integer nOldVal = ProcEnv.getProbability(curProc);
m_slideProbability.setValue((nOldVal == null) ? 0 : nOldVal);
m_notifier.showMsg(e1.getMessage(), false);
}
}
});
}
示例6: addBorderSetter
import javax.swing.JSlider; //导入依赖的package包/类
private void addBorderSetter(final JComponent s) {
if (s instanceof JTextField || s instanceof JSlider || s instanceof JComboBox || s instanceof AbstractButton) {
s.setFocusable(true);// sliders and combo boxes not normally focusable
s.addFocusListener(this);
// log.info("added border setter for "+s.getClass().getSimpleName());
} else if (s instanceof Container) {
Component[] components = s.getComponents();
for (Component c : components) {
// log.info("possibly adding border setter for "+c.getClass().getSimpleName());
if (c instanceof JComponent) {
addBorderSetter((JComponent) c);
}
}
}
}
示例7: accept
import javax.swing.JSlider; //导入依赖的package包/类
protected boolean accept(Component jc) {
if (extListener != null && extListener.accept(jc)) {
return true;
}
if (!(jc instanceof JComponent)) {
return false;
}
return isProbablyAContainer (jc) ||
jc instanceof JList ||
jc instanceof JComboBox ||
jc instanceof JTree ||
jc instanceof JToggleButton || //covers toggle, radio, checkbox
jc instanceof JTextComponent ||
jc instanceof JColorChooser ||
jc instanceof JSpinner ||
jc instanceof JSlider;
}
示例8: getControls
import javax.swing.JSlider; //导入依赖的package包/类
public Component getControls() {
final JSlider slider = new JSlider(JSlider.HORIZONTAL,0,100,opacity);
final HashMap<Integer,JLabel> labelTable = new HashMap<Integer,JLabel>();
labelTable.put(0, new JLabel("Transparent"));
labelTable.put(100, new JLabel("Opaque"));
slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);
// Note: JSlider uses the outdated Hashtable. Eventually Hashtable
// will be deprecated and we'll be able to use the HashMap directly.
slider.setLabelTable(new Hashtable<Integer,JLabel>(labelTable));
slider.setPaintLabels(true);
slider.setBorder(javax.swing.BorderFactory.createTitledBorder(name));
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
final JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
opacity = source.getValue();
}
}});
return slider;
}
示例9: DrivestrengthMainWindow
import javax.swing.JSlider; //导入依赖的package包/类
public DrivestrengthMainWindow() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
setLayout(new GridBagLayout());
setTitle("ASGDrivestrength");
setSize(500, 300);
JSlider percentageEnergySlider = new JSlider(JSlider.HORIZONTAL,
0, 100, 0);
JButton runButton = new JButton("Run");
add(percentageEnergySlider);
add(runButton);
setVisible(true);
}
示例10: Slider
import javax.swing.JSlider; //导入依赖的package包/类
/**
* @param prefix the text of the Label
* @param sufix thge text of the Label
* @param minvalue start vlaue
* @param maxvalue last value
* @param startvalue inital value
* @param komma 10^x offset for komma digits
*/
public Slider(String prefix, String sufix, int minvalue, int maxvalue, int startvalue, int komma, @Nullable ChangeListener cl,@Nullable Updater upd, boolean enabled) {//ChangeListener or Updater could be Null!
slider = new JSlider(minvalue, maxvalue, startvalue);
slider.addChangeListener(this);
if(prefix != null)
this.prefix = prefix;
if(sufix != null) {
this.sufix = sufix;
}
offset = komma;
label = new JLabel(getLabelText());
add(slider);
add(label);
listener = cl;
updater = upd;
slider.setEnabled(enabled);
defaultvalue = startvalue;
}
示例11: sliderStateChanged
import javax.swing.JSlider; //导入依赖的package包/类
/**
* when slider is moved, event is sent here. The slider is the 'master' of the value in the text field.
* Slider is linear scale, from pot min to pot max
*
* @param e
* the ChangeEvent
*/
private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_sliderStateChanged
if (sliderDontProcess) {
return;
}
// we can get a double send here if user presses uparrow key, resulting in new pot value,
// which updates the slider position, which ends up with a different bitvalue that makes a new
// pot value.
// See http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html
// System.out.println("slider state changed");
// slider is only source of ChangeEvents
JSlider s = (JSlider) evt.getSource();
// System.out.println("slider state changed for "+pot);
int v = s.getValue(); // slider value
if (v == 0) {
pot.setBitValue(0); // these pot chanages will come back to us as Observer events
// a problem because they will updateAappearance, which will change slider state
// and generate possibly a new slider changeevent
}
else {
v = sliderValueFromBitValue(s);
pot.setBitValue(v);
}
}
示例12: main
import javax.swing.JSlider; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
JSlider slider = new JSlider();
test(slider);
ThreadGroup group = new ThreadGroup("$$$");
Thread thread = new Thread(group, new Test6657026());
thread.start();
thread.join();
test(slider);
}
示例13: 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);
}
示例14: bitVal2SliderVal
import javax.swing.JSlider; //导入依赖的package包/类
/** Maps from bit value to linear/log slider value.
*
* @param v bit value.
* @param vmax max bit value.
* @param slider the slider for the value.
* @return the correct slider value.
*/
private int bitVal2SliderVal(int v, int vmax, JSlider slider) {
int s = 0;
if (v < knee) {
s = v;
} else {
double sm = slider.getMaximum();
double vm = vmax;
s = (int) (knee + Math.round((sm - knee) * log2((double) v - (knee - 1)) / log2(vm - (knee - 1))));
}
// log.info("bitValue=" + v + " -> sliderValue=" + s);
return s;
}
示例15: setMinorTickSpacing
import javax.swing.JSlider; //导入依赖的package包/类
/**
* Maps {@code JSlider.setMinorTickSpacing(int)} through queue
*/
public void setMinorTickSpacing(final int i) {
runMapping(new MapVoidAction("setMinorTickSpacing") {
@Override
public void map() {
((JSlider) getSource()).setMinorTickSpacing(i);
}
});
}