Java Code Examples for javax.swing.plaf.SliderUI

The following examples show how to use javax.swing.plaf.SliderUI. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pumpernickel   Source File: AngleSliderUIDemo.java    License: MIT License 6 votes vote down vote up
private void refreshAngleSlider() {
	SliderUI ui = new AngleSliderUI();
	angleSlider.setUI(ui);
	angleSlider.setEnabled(stateEnabled.isSelected());

	Dimension d = ui.getPreferredSize(angleSlider);
	int z = Math.max(d.width, d.height);

	int relativeValue = sizeSlider.getValue() - sizeSlider.getMinimum();
	int newValue = z + relativeValue;
	sizeSlider.getModel().setRangeProperties(newValue,
			sizeSlider.getModel().getExtent(), z, z + 100,
			sizeSlider.getModel().getValueIsAdjusting());

	angleSlider.setPreferredSize(new Dimension(newValue, newValue));
}
 
Example 2
Source Project: pumpernickel   Source File: BasicAudioPlayerUI.java    License: MIT License 6 votes vote down vote up
@Override
protected void notifyPlaybackProgress(AudioPlayerComponent apc,
		float timeElapsed, float timeAsFraction) {
	Fields fields = getFields(apc);
	int span = fields.playbackProgress.getMaximum()
			- fields.playbackProgress.getMinimum();
	int v = (int) (span * timeAsFraction + fields.playbackProgress
			.getMinimum());
	SliderUI ui = fields.playbackProgress.getUI();
	boolean isDragging = ui instanceof WaveformSliderUI ? ((WaveformSliderUI) ui)
			.isDragging() : false;
	if (!isDragging) {
		fields.playbackProgress.removeChangeListener(fields.sliderListener);
		fields.playbackProgress.setValue(v);
		fields.playbackProgress.addChangeListener(fields.sliderListener);
	}
	setIcon(fields.playButton, PAUSE_ICON);
}
 
Example 3
Source Project: dragonwell8_jdk   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source Project: TencentKona-8   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source Project: jdk8u60   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source Project: openjdk-jdk8u   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source Project: openjdk-jdk9   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.getUI()} through queue
 */
public SliderUI getUI() {
    return (runMapping(new MapAction<SliderUI>("getUI") {
        @Override
        public SliderUI map() {
            return ((JSlider) getSource()).getUI();
        }
    }));
}
 
Example 10
Source Project: openjdk-jdk9   Source File: JSliderOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JSlider.setUI(SliderUI)} through queue
 */
public void setUI(final SliderUI sliderUI) {
    runMapping(new MapVoidAction("setUI") {
        @Override
        public void map() {
            ((JSlider) getSource()).setUI(sliderUI);
        }
    });
}
 
Example 11
Source Project: jdk8u-jdk   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source Project: hottub   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source Project: openjdk-8-source   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Source Project: openjdk-8   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 15
Source Project: jdk8u_jdk   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 16
Source Project: jdk8u-jdk   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Source Project: jdk8u-dev-jdk   Source File: bug6848475.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Rectangle getThumbRectField() {
    try {
        SliderUI ui = slider.getUI();

        Field field = BasicSliderUI.class.getDeclaredField("thumbRect");

        field.setAccessible(true);

        return (Rectangle) field.get(ui);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 18
Source Project: darklaf   Source File: ThemeSettingsPanel.java    License: MIT License 4 votes vote down vote up
private JSlider createFontSlider() {
    JSlider fontSlider = new JSlider() {
        @Override
        public String getToolTipText(final MouseEvent event) {
            return getValue() + "%";
        }
    };
    ToolTipContext context = new ToolTipContext().setAlignment(Alignment.CENTER)
                                                 .setCenterAlignment(Alignment.NORTH)
                                                 .setUseBestFit(true)
                                                 .setToolTipRectSupplier(e -> {
                                                     SliderUI ui = fontSlider.getUI();
                                                     if (ui instanceof DarkSliderUI) {
                                                         Rectangle r = ((DarkSliderUI) ui).getThumbRect();
                                                         r.x -= 1;
                                                         return r;
                                                     }
                                                     return new Rectangle(0, 0, fontSlider.getWidth(),
                                                                          fontSlider.getHeight());
                                                 });
    fontSlider.putClientProperty(DarkSliderUI.KEY_INSTANT_SCROLL, true);
    fontSlider.putClientProperty(ToolTipConstants.KEY_CONTEXT, context);
    fontSlider.putClientProperty(ToolTipConstants.KEY_STYLE, ToolTipConstants.VARIANT_BALLOON);
    fontSlider.setToolTipText(String.valueOf(fontSlider.getValue()));
    fontSlider.setOrientation(JSlider.HORIZONTAL);
    fontSlider.setPaintTicks(true);
    fontSlider.setMinimum(FontSizePreset.TINY.getPercentage());
    fontSlider.setMaximum(FontSizePreset.HUGE.getPercentage());
    int tickSpacing = 25;
    Dictionary<Integer, JComponent> dict = fontSlider.createStandardLabels(tickSpacing);
    JLabel min = ((JLabel) dict.get(fontSlider.getMinimum()));
    UIUpdater.registerComponent(min);
    min.setText(resourceBundle.getString("label_font_smaller"));
    min.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    min.putClientProperty(DarkSliderUI.KEY_MANUAL_LABEL_ALIGN, true);

    JLabel mid = ((JLabel) dict.get(fontSlider.getMinimum() + tickSpacing));
    UIUpdater.registerComponent(mid);
    dict.remove(fontSlider.getMinimum() + tickSpacing);
    dict.put(FontSizePreset.NORMAL.getPercentage(), mid);
    mid.setText(resourceBundle.getString("label_font_default"));
    mid.setAlignmentX(JComponent.CENTER_ALIGNMENT);
    mid.setHorizontalTextPosition(JLabel.RIGHT);

    JLabel max = ((JLabel) dict.get(fontSlider.getMaximum()));
    max.putClientProperty(DarkSliderUI.KEY_MANUAL_LABEL_ALIGN, true);
    max.setText(resourceBundle.getString("label_font_bigger"));
    max.setAlignmentX(JComponent.RIGHT_ALIGNMENT);
    max.putClientProperty(DarkSliderUI.KEY_MANUAL_LABEL_ALIGN, true);
    UIUpdater.registerComponent(max);

    dict.remove(FontSizePreset.Small.getPercentage());
    dict.remove(FontSizePreset.SMALL.getPercentage());
    dict.remove(FontSizePreset.Large.getPercentage());
    dict.remove(FontSizePreset.LARGE.getPercentage());
    dict.remove(FontSizePreset.Huge.getPercentage());

    fontSlider.setLabelTable(dict);
    fontSlider.setMajorTickSpacing(tickSpacing);
    fontSlider.setMinorTickSpacing(tickSpacing);
    fontSlider.setPaintLabels(true);
    fontSlider.setSnapToTicks(true);
    return fontSlider;
}