List of utility methods to do JSlider
void | addVerticalMouseListener(final JPanel panel, final JSlider slider) add Vertical Mouse Listener slider.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); double percent = p.y / ((double) panel.getHeight()); int range = slider.getMaximum() - slider.getMinimum(); double newVal = range * percent; int result = (int) (slider.getMaximum() - newVal); ... |
void | adjustWithoutNotifyingListeners(JSlider slider, int value) adjust Without Notifying Listeners ChangeListener[] cl = slider.getChangeListeners(); if (cl != null) { for (ChangeListener x : cl) slider.removeChangeListener(x); slider.setValue(value); if (cl != null) { for (ChangeListener x : cl) ... |
void | ajustarValorDeslizador(JSlider sldActual, int valor) ajustar Valor Deslizador ChangeListener[] lista = sldActual.getChangeListeners(); for (ChangeListener clAct : lista) { sldActual.removeChangeListener(clAct); sldActual.setValue(valor); for (ChangeListener clAct : lista) { sldActual.addChangeListener(clAct); |
JFormattedTextField | buildIntegerFieldWithSlider(final JSlider matchingSlider) Builds a formatted text field with specified min and max, and attaches the slider to it via listeners. final JFormattedTextField returnValue = buildIntegerField(matchingSlider.getMinimum(), matchingSlider.getMaximum()); returnValue.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("value".equals(evt.getPropertyName())) { Number value = (Number) evt.getNewValue(); if (value != null) { ... |
JSlider | createJSlider(final BoundedRangeModel model) Creates a JSlider built using a DefaultBoundedRangeModel and containing a MouseWheelListener and some usual default settings final JSlider slider = new JSlider(model); slider.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { slider.setValue(-e.getWheelRotation() * model.getMaximum() / 100 + model.getValue()); }); slider.setPaintTicks(true); ... |
JPanel | createLabelField(String preText, String postText, JSlider s) create Label Field JPanel p = new JPanel(); JSpinner spin = new JSpinner(new SpinnerNumberModel(s.getValue(), s.getMinimum(), s.getMaximum(), 1)); spin.addChangeListener(ce -> { s.setValue((Integer) spin.getValue()); }); p.add(new JLabel(preText)); p.add(spin); p.add(new JLabel(postText)); ... |
JPanel | createSliderPanel(final JSlider slider, String label, int width) Creates a labeled panel containing a slider and considering a particular width final JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.setBorder(new TitledBorder(label)); p.setPreferredSize(new Dimension(width, 60)); p.add(slider); return p; |
void | fixWinSliderUI(JSlider s) fix Win Slider UI if (System.getProperty("os.name").toLowerCase().contains("win")) { s.setUI(new BasicSliderUI(s) { protected Dimension getThumbSize() { Dimension old = super.getThumbSize(); return new Dimension(old.width * 2, old.height); }); |
JPanel | makeLabelSliderPanelHorizontal(String text, JSlider slider) Returns a JPanel object containing a slider with description. JPanel panel = new JPanel(); JLabel label = new JLabel(text, JLabel.RIGHT); label.setMinimumSize(largeDescriptionsSize); label.setPreferredSize(largeDescriptionsSize); label.setMaximumSize(largeDescriptionsSize); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(label); panel.add(Box.createRigidArea(new Dimension(10, 0))); ... |
void | reapplyFontSize(JSlider slider) Apply the font size to the labels of a 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());
...
|