Search in sources :

Example 1 with BasicSliderUI

use of javax.swing.plaf.basic.BasicSliderUI in project jdk8u_jdk by JetBrains.

the class bug6794836 method run.

public void run() throws Exception {
    JSlider slider = new JSlider(0, Integer.MAX_VALUE);
    slider.setPaintLabels(true);
    JLabel minLabel = new JLabel("Min");
    JLabel maxLabel = new JLabel("Max");
    Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
    labelTable.put(Integer.MIN_VALUE, minLabel);
    labelTable.put(Integer.MAX_VALUE, maxLabel);
    slider.setLabelTable(labelTable);
    BasicSliderUI ui = (BasicSliderUI) slider.getUI();
    if (invokeMethod("getHighestValueLabel", ui) != maxLabel) {
        fail("invalid getHighestValueLabel result");
    }
    if (invokeMethod("getLowestValueLabel", ui) != minLabel) {
        fail("invalid getLowestValueLabel result");
    }
    System.out.println("The bug6794836 test passed");
}
Also used : Hashtable(java.util.Hashtable) BasicSliderUI(javax.swing.plaf.basic.BasicSliderUI)

Example 2 with BasicSliderUI

use of javax.swing.plaf.basic.BasicSliderUI in project JMRI by JMRI.

the class SliderSnap method createUI.

/**
     * Returns the UI as normal, but intercepts the call, so that a listener can
     * be attached
     *
     * @param c the slider component
     * @return a ComponentUI object with attached listener
     */
public static ComponentUI createUI(JComponent c) {
    if (c == null || sliderClass == null) {
        return null;
    }
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    try {
        Method m = (Method) defaults.get(sliderClass);
        if (m == null) {
            m = //NOI18N
            sliderClass.getMethod(//NOI18N
            "createUI", new Class<?>[] { JComponent.class });
            defaults.put(sliderClass, m);
        }
        ComponentUI uiObject = (ComponentUI) m.invoke(null, new Object[] { c });
        if (uiObject instanceof BasicSliderUI) {
            c.addHierarchyListener(new MouseAttacher());
        }
        return uiObject;
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : UIDefaults(javax.swing.UIDefaults) JComponent(javax.swing.JComponent) BasicSliderUI(javax.swing.plaf.basic.BasicSliderUI) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentUI(javax.swing.plaf.ComponentUI)

Aggregations

BasicSliderUI (javax.swing.plaf.basic.BasicSliderUI)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Hashtable (java.util.Hashtable)1 JComponent (javax.swing.JComponent)1 UIDefaults (javax.swing.UIDefaults)1 ComponentUI (javax.swing.plaf.ComponentUI)1