Java Code Examples for javax.swing.JSlider

The following are top voted examples for showing how to use javax.swing.JSlider. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: VISNode   File: InputEditor.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Project: incubator-netbeans   File: BindingDesignSupportImpl.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 3
Project: rapidminer   File: ExtendedJSliderToolTips.java   Source Code and License 6 votes vote down vote up
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;
			}
		}
	});
}
 
Example 4
Project: freecol   File: RangeOptionUI.java   Source Code and License 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 5
Project: sstore-soft   File: ProcGui.java   Source Code and License 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example 6
Project: jaer   File: PotPanel.java   Source Code and License 6 votes vote down vote up
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);
                }
            }
        }
    }
 
Example 7
Project: VASSAL-src   File: GenericListener.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 8
Project: VASSAL-src   File: ZoneHighlight.java   Source Code and License 6 votes vote down vote up
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;
    }
 
Example 9
Project: asgdrivestrength   File: DrivestrengthMainWindow.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 10
Project: FreeCol   File: RangeOptionUI.java   Source Code and License 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 11
Project: ClashRoyale-Bot   File: UI.java   Source Code and License 6 votes vote down vote up
/**
 * @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;
}
 
Example 12
Project: jaer   File: SimpleVPotSliderTextControl.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 13
Project: jdk8u-jdk   File: Test6657026.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 14
Project: incubator-netbeans   File: JComponentBuilders.java   Source Code and License 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 15
Project: jaer   File: ConfigurableIPotGUIControl.java   Source Code and License 5 votes vote down vote up
/** 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;
    }
 
Example 16
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
        }
    });
}
 
Example 17
Project: rapidminer   File: SliderUI.java   Source Code and License 5 votes vote down vote up
@Override
protected void uninstallListeners(JSlider slider) {
	if (this.thumbPressedListener != null) {
		slider.removeMouseListener(this.thumbPressedListener);
		this.thumbPressedListener = null;
	}
	super.uninstallListeners(slider);
}
 
Example 18
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.getMajorTickSpacing()} through queue
 */
public int getMajorTickSpacing() {
    return (runMapping(new MapIntegerAction("getMajorTickSpacing") {
        @Override
        public int map() {
            return ((JSlider) getSource()).getMajorTickSpacing();
        }
    }));
}
 
Example 19
Project: marathonv5   File: RSliderTest.java   Source Code and License 5 votes vote down vote up
public void sliderTest() {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override public void run() {
            JSlider slider = (JSlider) ComponentUtils.findComponent(JSlider.class, frame);
            slider.setValue(25);
            RSlider rslider = new RSlider(slider, null, null, lr);
            rslider.focusLost(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("25", call.getState());
}
 
Example 20
Project: GlitchKernel   File: GlitchUIManager.java   Source Code and License 5 votes vote down vote up
public void changeSliderValue(JComponent jComponent)
{
	if(jComponent instanceof JSlider && !((JSlider) jComponent).getValueIsAdjusting() && this.glitchArt.jAlgorithmList.getSelectedIndex() >= 0)
	{
		refreshSliderValues(true);
	}
	else if(jComponent instanceof JComboBox && this.glitchArt.jAlgorithmList.getSelectedIndex() >= 0)
	{
		refreshSliderValues(true);
	}
}
 
Example 21
Project: EditCalculateAndChart   File: grPlt.java   Source Code and License 5 votes vote down vote up
@Override
    public void stateChanged(ChangeEvent e) {
                       JSlider source = (JSlider)e.getSource();
        if (!source.getValueIsAdjusting()) {
            int fps = source.getValue();
            String varName = source.getName();
            //regenerate data set and repaint
               int i;
            for( i = 1; i<vars.size();i++)
               if(vars.get(i).contentEquals(varName))
                   break;
           varsValues.set(i,rangesLeft.get(i).add(steps.get(i).multiply(new BigDecimal(fps))));
          //System.out.println(i); 
String   chartName=FunctionToPlot;


    for(int j = 1; j < vars.size();j++){
        chartName = SmartReplace.get(chartName,vars.get(j),varsValues.get(j).toPlainString()); 
         //chartName = chartName.replace(vars.get(j),varsValues.get(j).toPlainString()); 
        sliderLabels[j-1].setText(vars.get(j)+'='+varsValues.get(j).toPlainString());
      }
try{
       chartP.setChart(createChart(getDataset(),chartName));
}
catch(Exception ex){
 System.out.println(ex.getMessage());
}
    // chartPanel = new ChartPanel(chart);
    
//contentPanel.repaint();
//this.repaint();
//this.setVisible(true);
}
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
 
Example 22
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.getMinorTickSpacing()} through queue
 */
public int getMinorTickSpacing() {
    return (runMapping(new MapIntegerAction("getMinorTickSpacing") {
        @Override
        public int map() {
            return ((JSlider) getSource()).getMinorTickSpacing();
        }
    }));
}
 
Example 23
Project: openjdk-jdk10   File: JSliderDriver.java   Source Code and License 5 votes vote down vote up
private Point getClickPoint(ComponentOperator oper, int direction, int orientation) {
    int x, y;
    boolean inverted = ((JSliderOperator) oper).getInverted();
    int realDirection = ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
    if (inverted) {
        if (direction == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
            realDirection = ScrollAdjuster.DECREASE_SCROLL_DIRECTION;
        } else if (direction == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
            realDirection = ScrollAdjuster.INCREASE_SCROLL_DIRECTION;
        } else {
            return null;
        }
    } else {
        realDirection = direction;
    }
    if (orientation == JSlider.HORIZONTAL) {
        if (realDirection == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
            x = oper.getWidth() - 1;
        } else if (realDirection == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
            x = 0;
        } else {
            return null;
        }
        y = oper.getHeight() / 2;
    } else if (orientation == JSlider.VERTICAL) {
        if (realDirection == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
            y = 0;
        } else if (realDirection == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
            y = oper.getHeight() - 1;
        } else {
            return null;
        }
        x = oper.getWidth() / 2;
    } else {
        return null;
    }
    return new Point(x, y);
}
 
Example 24
Project: openjdk-jdk10   File: TranslucentShapedFrameTest.java   Source Code and License 5 votes vote down vote up
private void transparencySldStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_transparencySldStateChanged
    JSlider source = (JSlider)evt.getSource();
        int transl = transparencySld.getValue();
        if (testFrame != null) {
            testFrame.setOpacity((float)transl/100f);
        }
}
 
Example 25
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.getPaintLabels()} through queue
 */
public boolean getPaintLabels() {
    return (runMapping(new MapBooleanAction("getPaintLabels") {
        @Override
        public boolean map() {
            return ((JSlider) getSource()).getPaintLabels();
        }
    }));
}
 
Example 26
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.setValue(int)} through queue
 */
public void setValue(final int i) {
    runMapping(new MapVoidAction("setValue") {
        @Override
        public void map() {
            ((JSlider) getSource()).setValue(i);
        }
    });
}
 
Example 27
Project: openjdk-jdk10   File: CAccessible.java   Source Code and License 5 votes vote down vote up
public void addNotificationListeners(Component c) {
    if (c instanceof Accessible) {
        AccessibleContext ac = ((Accessible)c).getAccessibleContext();
        ac.addPropertyChangeListener(new AXChangeNotifier());
    }
    if (c instanceof JProgressBar) {
        JProgressBar pb = (JProgressBar) c;
        pb.addChangeListener(new AXProgressChangeNotifier());
    } else if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        slider.addChangeListener(new AXProgressChangeNotifier());
    }
}
 
Example 28
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.createStandardLabels(int, int)} through queue
 */
public Hashtable<?, ?> createStandardLabels(final int i, final int i1) {
    return ((Hashtable<?, ?>) runMapping(new MapAction<Object>("createStandardLabels") {
        @Override
        public Object map() {
            return ((JSlider) getSource()).createStandardLabels(i, i1);
        }
    }));
}
 
Example 29
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.setExtent(int)} through queue
 */
public void setExtent(final int i) {
    runMapping(new MapVoidAction("setExtent") {
        @Override
        public void map() {
            ((JSlider) getSource()).setExtent(i);
        }
    });
}
 
Example 30
Project: jaer   File: ConfigurableIPotGUIControl.java   Source Code and License 5 votes vote down vote up
/** Maps from linear slider to linear/exponential bit value.
     *
     * @param vmax max bit value.
     * @param slider the slider.
     * @return the bit value.
     */
    private int sliderVal2BitVal(int vmax, JSlider slider) {
        int v = 0;
        int s = slider.getValue();
        if (s < knee) {
            v = s;
        } else {
            double sm = slider.getMaximum();
            double vm = vmax;
            v = (int) (knee - 1 + Math.round(Math.pow(2, (s - knee) * (log2(vm - (knee - 1))) / (sm - knee))));
        }
//        log.info("sliderValue=" + s + " -> bitValue=" + v);
        return v;
    }
 
Example 31
Project: sumo   File: MultiThumbSlider.java   Source Code and License 5 votes vote down vote up
protected void uninstallListeners(JSlider slider) {
    slider.removeMouseListener(mThumbTrackListener);
    slider.removeMouseMotionListener(mThumbTrackListener);
    slider.removeFocusListener(focusListener);
    slider.removeComponentListener(componentListener);
    slider.removePropertyChangeListener(propertyChangeListener);
    slider.getModel().removeChangeListener(changeListener);
}
 
Example 32
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.setValueIsAdjusting(boolean)} through queue
 */
public void setValueIsAdjusting(final boolean b) {
    runMapping(new MapVoidAction("setValueIsAdjusting") {
        @Override
        public void map() {
            ((JSlider) getSource()).setValueIsAdjusting(b);
        }
    });
}
 
Example 33
Project: OpenDA   File: Query.java   Source Code and License 5 votes vote down vote up
/** Get the current value in the entry with the given name
 *  and return as an integer.  If the entry is not a line,
 *  choice, or slider, then throw an exception.
 *  If it is a choice or radio button, then return the
 *  index of the first selected item.
 *  @return The value currently in the entry as an integer.
 *  @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 NumberFormatException If the value of the entry cannot
 *   be converted to an integer.  This is a runtime exception, so it
 *   need not be declared explicitly.
 *  @exception IllegalArgumentException If the entry is not a
 *   choice, line, or slider.  This is a runtime exception, so it
 *   need not be declared explicitly.
 */
public int getIntValue(String name)
    throws
        IllegalArgumentException,
        NoSuchElementException,
        NumberFormatException {
    Object result = _entries.get(name);
    if (result == null) {
        throw new NoSuchElementException(
            "No item named \"" + name + " \" in the query box.");
    }
    if (result instanceof JTextField) {
        return (new Integer(((JTextField) result).getText())).intValue();
    } else if (result instanceof JSlider) {
        return ((JSlider) result).getValue();
    } else if (result instanceof JComboBox) {
        return ((JComboBox) result).getSelectedIndex();
    } else if (result instanceof JRadioButton[]) {
        // Regrettably, ButtonGroup gives no way to determine
        // which button is selected, so we have to search...
        JRadioButton[] buttons = (JRadioButton[]) result;
        for (int i = 0; i < buttons.length; i++) {
            if (buttons[i].isSelected()) {
                return i;
            }
        }
        // In theory, we shouldn't get here, but the compiler
        // is unhappy without a return.
        return -1;
    } else {
        throw new IllegalArgumentException(
            "Item named \""
                + name
                + "\" is not a text line or slider, and hence "
                + "cannot be converted to "
                + "an integer value.");
    }
}
 
Example 34
Project: openjdk-jdk10   File: MotifSliderUI.java   Source Code and License 5 votes vote down vote up
protected Dimension getThumbSize() {
    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        return new Dimension( 30, 15 );
    }
    else {
        return new Dimension( 15, 30 );
    }
}
 
Example 35
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.setSnapToTicks(boolean)} through queue
 */
public void setSnapToTicks(final boolean b) {
    runMapping(new MapVoidAction("setSnapToTicks") {
        @Override
        public void map() {
            ((JSlider) getSource()).setSnapToTicks(b);
        }
    });
}
 
Example 36
Project: openjdk-jdk10   File: JSliderOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JSlider.setLabelTable(Dictionary)} through queue
 */
public void setLabelTable(final Dictionary<?, ?> dictionary) {
    runMapping(new MapVoidAction("setLabelTable") {
        @Override
        public void map() {
            ((JSlider) getSource()).setLabelTable(dictionary);
        }
    });
}
 
Example 37
Project: jaer   File: ShiftedSourceControlsCF.java   Source Code and License 5 votes vote down vote up
/** 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;
        double sm = slider.getMaximum();
        double vm = vmax;
        s = (int) Math.round(sm*v/vm);;
//        log.info("bitValue=" + v + " -> sliderValue=" + s);
        return s;
    }
 
Example 38
Project: TreeFlood   File: LocalStorageExplorationGUIController.java   Source Code and License 5 votes vote down vote up
@Override
public void stateChanged(final ChangeEvent e) {
	if (!(e.getSource() instanceof JSlider)) {
		return;
	}
	final JSlider sizeSlider = (JSlider) e.getSource();
	this.changeTreeProportions(sizeSlider.getValue());
}
 
Example 39
Project: OpenJSharp   File: MotifSliderUI.java   Source Code and License 5 votes vote down vote up
protected Dimension getThumbSize() {
    if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
        return new Dimension( 30, 15 );
    }
    else {
        return new Dimension( 15, 30 );
    }
}
 
Example 40
Project: MapAnalyst   File: SliderUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Apply the font size to the labels of a slider. This must be called after
 * the labels of a slider are changed.
 *
 * First set up the label hash table and add it to the slider. Then, after
 * the slider has been added to a parent window and had its UI assigned,
 * call this method to change the label sizes.
 *
 * http://nadeausoftware.com/node/93#Settingsliderlabelfontsizes
 * 
 * @param slider
 */
public static void reapplyFontSize(JSlider slider) {

    Font font = slider.getFont();
    Dictionary dict = slider.getLabelTable();
    Enumeration keys = dict.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Component label = (Component) dict.get(key);
        label.setFont(font);
        label.setSize(label.getPreferredSize());
    }

}