javax.swing.JSlider.getValue()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中javax.swing.JSlider.getValue()方法的一些代码示例,展示了JSlider.getValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSlider.getValue()方法的具体详情如下:
包路径:javax.swing.JSlider
类名称:JSlider
方法名:getValue

JSlider.getValue介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame();
final JTextField text = new JTextField(20);
final JSlider slider = new JSlider(0, 100, 0);
slider.addChangeListener(new ChangeListener(){
  @Override
  public void stateChanged(ChangeEvent e) {
    text.setText(String.valueOf(slider.getValue()));
frame.add(text, BorderLayout.NORTH);
frame.add(slider, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();

代码示例来源:origin: magefree/mage

JPanel sliderPanel = new JPanel(new GridBagLayout());
sliderPanel.setOpaque(false);
cardSizeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 50);
cardSizeSlider.setOpaque(false);
cardSizeSlider.setPreferredSize(new Dimension(100, (int) cardSizeSlider.getPreferredSize().getHeight()));
cardSizeSlider.addChangeListener(e -> {
  if (!cardSizeSlider.getValueIsAdjusting()) {
    float sliderFrac = ((float) (cardSizeSlider.getValue() - 50)) / 50;

代码示例来源:origin: stackoverflow.com

class Window extends JFrame {
  private JSlider slider;
  // a reference to the other class needs to be final
  private final Test testClass;
  public Window(Test incomingReference) {
    // set the reference
    this.testClass = incomingReference;
    // JSlider stuff
    slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 1);
    slider.addChangeListener(new ChangeListener() {
      @Override public void stateChanged(ChangeEvent e) {
        JSlider src = (JSlider) e.getSource();
        if (src.getValueIsAdjusting()) return;
        testClass.setSomeVariable(src.getValue());
        System.out.println(testClass.getSomeVariable());
      }
    });
    // window stuff
    JFrame window = new JFrame("JSlider Test");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setSize(800, 600);
    window.add(slider);
    window.setVisible(true);
  }
}

代码示例来源:origin: com.io7m.jcamera/com.io7m.jcamera.examples.jogl

CameraFloatSlider(
 final String in_label,
 final double in_minimum,
 final double in_maximum)
{
 this.label = new JLabel(NullCheck.notNull(in_label, "ForwardLabel"));
 this.group = new RowGroup();
 this.maximum = in_maximum;
 this.minimum = in_minimum;
 this.field = new JTextField(Double.toString(in_minimum));
 this.slider = new JSlider(SwingConstants.HORIZONTAL);
 this.slider.setMinimum(0);
 this.slider.setMaximum(100);
 this.slider.setValue(0);
 this.slider.addChangeListener(ev -> {
  final int slider_current = CameraFloatSlider.this.slider.getValue();
  this.current = convertFromSlider(slider_current, in_minimum, in_maximum);
  this.refreshText();
  this.callListener();
 });
 this.field.setEditable(false);
}

代码示例来源:origin: stackoverflow.com

private JSlider js4 = new JSlider(1, 5);
private int state = js4.getValue();
  JFrame frame = new JFrame("Sample Sliders");
  ...
    @Override
    public void actionPerformed(ActionEvent e) {
      state = js4.getValue();
      System.out.println("new state: " + state);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new FadePane());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
slider = new JSlider(0, 100);
setLayout(new BorderLayout());
add(slider, BorderLayout.SOUTH);
slider.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent e) {
    progress = ((float)slider.getValue() / 100f);
    repaint();

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception {

  final URL lenna =
    new URL("http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png");

  final JSlider slider = new JSlider(0, 1000, 500);
  final ImageComponent image = new ImageComponent(lenna);
  slider.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(ChangeEvent e) {
      image.setZoom(2. * slider.getValue() / slider.getMaximum());
    }
  });

  JFrame frame = new JFrame("Test");
  frame.add(slider, BorderLayout.NORTH);

  frame.add(new JScrollPane(image));

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(400, 300);
  frame.setVisible(true);
}

代码示例来源:origin: nroduit/Weasis

JSlider createSlider(final FloatControl c) {
  if (c == null) {
    return null;
  }
  final JSlider s = new JSlider(0, 1000);
  final float min = c.getMinimum();
  final float max = c.getMaximum();
  final float width = max - min;
  float fval = c.getValue();
  s.setValue((int) ((fval - min) / width * 1000));
  java.util.Hashtable<Integer, JLabel> labels = new java.util.Hashtable<>(3);
  labels.put(0, new JLabel(c.getMinLabel()));
  labels.put(500, new JLabel(c.getMidLabel()));
  labels.put(1000, new JLabel(c.getMaxLabel()));
  s.setLabelTable(labels);
  s.setPaintLabels(true);
  s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits())); //$NON-NLS-1$
  s.addChangeListener(e -> {
    int i = s.getValue();
    float f = min + (i * width / 1000.0f);
    c.setValue(f);
  });
  return s;
}

代码示例来源:origin: stackoverflow.com

quality = new JSlider(JSlider.VERTICAL, 0, 100, 75);
quality.setSnapToTicks(true);
quality.setPaintTicks(true);
quality.setMajorTickSpacing(10);
quality.setMinorTickSpacing(5);
quality.addChangeListener( new ChangeListener(){
  public void stateChanged(ChangeEvent ce) {
    updateImages();
gui.add(quality, BorderLayout.WEST);
dithering = new JCheckBox("Dithering", false);
controls.add(antialiasing);
controls.add(fractionalMetrics);
float qualityFloat = (float)quality.getValue()/100f;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
builder.append(jpgSize);
builder.append(" bytes \tquality: ");
builder.append(quality.getValue());

代码示例来源:origin: stackoverflow.com

final Image logo = ImageIO.read(new URL("http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png"));
final Dimension dim = new Dimension(logo.getWidth(null), logo.getHeight(null));
final JFrame frame = new JFrame();
frame.add(new JPanel() {
  @Override
  @Override
  public void stateChanged(ChangeEvent e) {
    dim.width = xSlider.getValue();
    dim.height = ySlider.getValue();
    frame.repaint();
xSlider.addChangeListener(cl);
ySlider.addChangeListener(cl);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();

代码示例来源:origin: cytoscape.coreplugins/manual-layout

jLabel.setPreferredSize(new Dimension(120, 50));
jSlider = new JSlider();
jSlider.setMaximum(360);
jSlider.setMajorTickSpacing(90);
jSlider.setValue(0);
jSlider.setPreferredSize(new Dimension(120, 50));
jSlider.addChangeListener(this);
prevValue = jSlider.getValue();

代码示例来源:origin: stackoverflow.com

getContentPane().add(bp);
validate();
    f.setMinimumSize( f.getSize() );
    f.setLocationByPlatform(true);
    f.setVisible(true);
options.add( pSampleRate );
    clip.getControl( FloatControl.Type.MASTER_GAIN );
  final JSlider volume = new JSlider(
    JSlider.VERTICAL,
    (int)control.getMinimum(),
    );
  volume.setToolTipText("Volume of beep");
  volume.addChangeListener( new ChangeListener(){
    public void stateChanged(ChangeEvent ce) {
      control.setValue( volume.getValue() );
Integer sR = (Integer)sampleRate.getSelectedItem();
int intST = sR.intValue();
int intFPW = framesPerWavelength.getValue();
int intFPW = framesPerWavelength.getValue();

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new TestLayout());
final JSlider slider = new JSlider();
slider.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent e) {
    StringBuilder sb = new StringBuilder(Integer.toString(slider.getValue()));
    while (sb.length() < 3) {
      sb.insert(0, "0");

代码示例来源:origin: org.cytoscape/manual-layout-impl

jLabel.setPreferredSize(new Dimension(120, 50));
jSlider = new JSlider();
jSlider.setMaximum(360);
jSlider.setMajorTickSpacing(90);
jSlider.setValue(0);
jSlider.setPreferredSize(new Dimension(120, 50));
jSlider.addChangeListener(this);
prevValue = jSlider.getValue();

代码示例来源:origin: stackoverflow.com

FloatControl.Type.MASTER_GAIN);
      VolumeSlider vs = new VolumeSlider(volCtrl);
      gui.add( new JLabel(volCtrl.toString()) );
      gui.add( vs.getVolume() );
      System.out.println(
          "    volCtrl.getValue() = " + volCtrl.getValue());
volume = new JSlider(
    (int) volumeControl.getMinimum() * 100,
    (int) volumeControl.getMaximum() * 100,
    float val = volume.getValue() / 100f;
    volumeControl.setValue(val);
    System.out.println(
volume.addChangeListener(listener);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new ExamplePane());
slider = new JSlider(0, 360);
slider.setValue(0);
slider.addChangeListener(new ChangeListener() {
  @Override
  public void stateChanged(ChangeEvent e) {
    transformModel.setRotation(Math.toRadians(slider.getValue()));

代码示例来源:origin: stackoverflow.com

clip.getControl(FloatControl.Type.MASTER_GAIN);
final JSlider volume = new JSlider(
    JSlider.HORIZONTAL,
    (int) control.getMinimum(),
    (int) control.getMaximum(),
    (int) control.getValue());
volume.addChangeListener(new ChangeListener() {
    control.setValue(volume.getValue());

代码示例来源:origin: stackoverflow.com

private static JFrame frame = new JFrame("Sample Sliders");
private static JSlider slider = new JSlider(1,5);
private static JButton button =new JButton("Button");
private static int saveNumberHere;
    public void run() {
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      slider.addChangeListener(sliderListener);
      ChangeListener buttonListener = new ButthonChangeListener();
      button.addChangeListener(buttonListener);
      frame.add(slider, BorderLayout.CENTER);
      frame.add(button, BorderLayout.SOUTH);
      frame.setSize(400, 300);
      frame.setVisible(true);
  public void stateChanged(ChangeEvent changeEvent) {
    if (!slider.getValueIsAdjusting()) {
      System.out.println ("Slider changed: " +         slider.getValue());
    saveNumberHere = slider.getValue();

代码示例来源:origin: stackoverflow.com

private JSlider sliderA = new JSlider(JSlider.HORIZONTAL, 0, 20, 5);
private JSlider sliderB = new JSlider(JSlider.HORIZONTAL, 0, 20, 15);
private JSlider[] sliders = {sliderA, sliderB};
private String[] titles = {"Point A", "Point B"};
   sliders[i].setPaintTicks(true);
   sliders[i].setPaintLabels(true);             
   sliders[i].addChangeListener(changeListeners[i]);             
   add(sliders[i]);             
 @Override
 public void stateChanged(ChangeEvent cEvt) {
   if (sliderA.getValue() >= sliderB.getValue()) {
    sliderB.setValue(sliderA.getValue() + 1);
 @Override
 public void stateChanged(ChangeEvent cEvt) {
   if (sliderA.getValue() >= sliderB.getValue()) {
    sliderA.setValue(sliderB.getValue() - 1);
 JFrame frame = new JFrame("SliderExample2");
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.getContentPane().add(new SliderExample2());
 frame.pack();
 frame.setLocationRelativeTo(null);
 frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

private JSlider sliderA = new JSlider(JSlider.HORIZONTAL, 0, 20, 5);
private JSlider sliderB = new JSlider(JSlider.HORIZONTAL, 0, 20, 15);
private JSlider[] sliders = {sliderA, sliderB};
private String[] titles = {"Point A", "Point B"};
   sliders[i].setPaintLabels(true);
   sliders[i].setSnapToTicks(true);
   sliders[i].addChangeListener(changeListeners[i]);             
   add(sliders[i]);             
 @Override
 public void stateChanged(ChangeEvent cEvt) {
   if (sliderA.getValue() >= sliderB.getValue()) {
    sliderA.setValue(sliderB.getValue());
 @Override
 public void stateChanged(ChangeEvent cEvt) {
   if (sliderA.getValue() >= sliderB.getValue()) {
    sliderB.setValue(sliderA.getValue());
 JFrame frame = new JFrame("SliderExample3");
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.getContentPane().add(new SliderExample3());
 frame.pack();
 frame.setLocationRelativeTo(null);
 frame.setVisible(true);

相关文章

JSlider类方法