public bug6401380() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); slider = new JSlider(); slider.setMajorTickSpacing(0); slider.setMaximum(50); slider.setMinorTickSpacing(10); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setSnapToTicks(true); // MetalSliderUI overrides scrollDueToClickInTrack() method // so this test doens't work for Metal slider.setUI(new BasicSliderUI(slider)); add(slider); setSize(200, 200); }
/** * Simple constructor. * * @param slider * The associated slider. */ public TrackableSlider(JSlider slider, ButtonModel transitionModel) { this.slider = slider; this.transitionModel = transitionModel; SliderUI sliderUI = slider.getUI(); if (sliderUI instanceof BasicSliderUI) { try { this.thumbRectField = BasicSliderUI.class .getDeclaredField("thumbRect"); this.thumbRectField.setAccessible(true); } catch (Exception exc) { this.thumbRectField = null; } } this.stateTransitionTracker = new StateTransitionTracker( this.slider, this.transitionModel); }
public static void fixWinSliderUI(JSlider s) { 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); } }); } }
/** * Returns the frames-per-second slider for the animation dialog. */ final JPanel getAnimationPanel() { // lazily create the label if (this.animationPanel == null) { JLabel label = new JLabel("Animation Speed"); label.setAlignmentX(Component.CENTER_ALIGNMENT); final JSlider slider = new JSlider(SwingConstants.HORIZONTAL, 1, 10, 2) { @Override public void updateUI() { setUI(BasicSliderUI.createUI(this)); } }; slider.setMajorTickSpacing(9); slider.setMinorTickSpacing(1); slider.setSnapToTicks(true); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setFocusable(false); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int speed = slider.getValue(); setSpeed(speed); } }); slider.setAlignmentX(Component.CENTER_ALIGNMENT); this.animationPanel = new JPanel(); this.animationPanel.setLayout(new BoxLayout(this.animationPanel, BoxLayout.Y_AXIS)); this.animationPanel.add(label); this.animationPanel.add(slider); } return this.animationPanel; }
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); } }
public MThumbSliderAdditionalUI(BasicSliderUI ui) { this.ui = ui; }
protected BasicSliderUI.TrackListener createTrackListener(final JSlider s) { return new TrackListener(); }
private void run() throws InterruptedException, InvocationTargetException { SwingUtilities.invokeAndWait(new Runnable() { public void run() { for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) { try { UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); } catch (Exception e) { fail(e.getMessage()); } BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB); // Test 1 JSlider slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); // Test 2 slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); // Test 3 slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setOrientation(JSlider.VERTICAL); slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); // Test 4 slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setOrientation(JSlider.VERTICAL); slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); countDownLatch.countDown(); } } }); if (countDownLatch.await(3000, TimeUnit.MILLISECONDS)) { System.out.println("bug6794831 passed"); } else { fail("bug6794831 failed"); } }
private void run() throws InterruptedException { SwingUtilities.invokeLater(new Runnable() { public void run() { for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) { try { UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); } catch (Exception e) { fail(e.getMessage()); } BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB); // Test 1 JSlider slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); // Test 2 slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); // Test 3 slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setOrientation(JSlider.VERTICAL); slider.setMajorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); // Test 4 slider = new JSlider(0, Integer.MAX_VALUE - 1, 0); slider.setOrientation(JSlider.VERTICAL); slider.setMinorTickSpacing((Integer.MAX_VALUE - 1) / 4); slider.setPaintTicks(true); ((BasicSliderUI) slider.getUI()).paintTicks(image.getGraphics()); countDownLatch.countDown(); } } }); if (countDownLatch.await(3000, TimeUnit.MILLISECONDS)) { System.out.println("bug6794831 passed"); } else { fail("bug6794831 failed"); } }