The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JSlider  [7 examples]

e797. Showing Tick Marks on a JSlider Component

The slider supports two levels of tick marks, major and minor. Typically, the minor tick-mark spacing is smaller than the major tick-mark spacing. Also, the minor tick-mark spacing is a multiple of the major tick-mark spacing. However, the slider does not enforce any of these constraints.
    // Create a horizontal slider that moves left-to-right
    JSlider slider = new JSlider();
    // Determine if currently showing ticks
    boolean b = slider.getPaintTicks(); // false
    
    // Show tick marks
    slider.setPaintTicks(true);
    
    // Set major tick marks every 25 units
    int tickSpacing = 25;
    slider.setMajorTickSpacing(tickSpacing);
    
    // Set minor tick marks every 5 units
    tickSpacing = 5;
    slider.setMinorTickSpacing(tickSpacing);

 Related Examples
e794. Creating a JSlider Component
e795. Getting and Setting the Values of a JSlider Component
e796. Setting the Orientation of a JSlider Component
e798. Showing Tick-Mark Labels on a JSlider Component
e799. Constraining JSlider Component Values to Tick Marks
e800. Listening for Value Changes in a JSlider Component

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.