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");
}
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);
}
}
Aggregations