List of usage examples for javax.swing JSlider createStandardLabels
public Hashtable<Integer, JComponent> createStandardLabels(int increment, int start)
From source file:Main.java
public static void setTickMarkers(JSlider slider) { final int min = slider.getMinimum(); final int max = slider.getMaximum(); final int delta = max - min; if (delta > 0) { final int sliderSize; if (slider.getOrientation() == SwingConstants.HORIZONTAL) sliderSize = slider.getPreferredSize().width; else// w w w . ja va 2 s . c om sliderSize = slider.getPreferredSize().height; // adjust ticks space on slider final int majTick = findBestMajTickSpace(sliderSize, delta); slider.setMinorTickSpacing(Math.max(1, majTick / 5)); slider.setMajorTickSpacing(majTick); slider.setLabelTable(slider.createStandardLabels(slider.getMajorTickSpacing(), majTick)); } }
From source file:JXTransformer.java
private JPanel createDemoPanel() { JPanel buttonPanel = new JPanel(new GridLayout(3, 2)); TitledBorder titledBorder = BorderFactory.createTitledBorder("Try three sliders below !"); Font titleFont = titledBorder.getTitleFont(); titledBorder.setTitleFont(titleFont.deriveFont(titleFont.getSize2D() + 10)); titledBorder.setTitleJustification(TitledBorder.CENTER); buttonPanel.setBorder(titledBorder); JButton b = new JButton("JButton"); b.setPreferredSize(new Dimension(100, 50)); buttonPanel.add(createTransformer(b)); Vector<String> v = new Vector<String>(); v.add("One"); v.add("Two"); v.add("Three"); JList list = new JList(v); buttonPanel.add(createTransformer(list)); buttonPanel.add(createTransformer(new JCheckBox("JCheckBox"))); JSlider slider = new JSlider(0, 100); slider.setLabelTable(slider.createStandardLabels(25, 0)); slider.setPaintLabels(true);//from w w w. j a v a2 s . c om slider.setPaintTicks(true); slider.setMajorTickSpacing(10); buttonPanel.add(createTransformer(slider)); buttonPanel.add(createTransformer(new JRadioButton("JRadioButton"))); final JLabel label = new JLabel("JLabel"); label.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { Font font = label.getFont(); label.setFont(font.deriveFont(font.getSize2D() + 10)); } public void mouseExited(MouseEvent e) { Font font = label.getFont(); label.setFont(font.deriveFont(font.getSize2D() - 10)); } }); buttonPanel.add(createTransformer(label)); return buttonPanel; }