List of usage examples for javax.swing JSlider setPaintTrack
@BeanProperty(visualUpdate = true, description = "If true, the track is painted on the slider.") public void setPaintTrack(boolean b)
From source file:Main.java
public static void main(String[] argv) throws Exception { JSlider slider = new JSlider(); slider.setPaintTrack(false); }
From source file:SampleSliders.java
public static void main(String args[]) { String title = (args.length == 0 ? "Sample Slider" : args[0]); JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider js1 = new JSlider(); js1.putClientProperty("JSlider.isFilled", Boolean.TRUE); JSlider js2 = new JSlider(); js2.setMajorTickSpacing(25);/*from ww w . ja v a2 s. c om*/ js2.setPaintTicks(true); js2.setSnapToTicks(true); JSlider js3 = new JSlider(JSlider.VERTICAL); js3.setPaintTrack(false); js3.setMinorTickSpacing(5); js3.setMajorTickSpacing(10); js3.setPaintTicks(true); js3.setPaintLabels(true); js3.setSnapToTicks(true); JSlider js4 = new JSlider(JSlider.VERTICAL); Hashtable table = new Hashtable(); table.put(new Integer(0), new JLabel(new DiamondIcon(Color.red))); table.put(new Integer(10), new JLabel("Ten")); table.put(new Integer(25), new JLabel("Twenty-Five")); table.put(new Integer(34), new JLabel("Thirty-Four")); table.put(new Integer(52), new JLabel("Fifty-Two")); table.put(new Integer(70), new JLabel("Seventy")); table.put(new Integer(82), new JLabel("Eighty-Two")); table.put(new Integer(100), new JLabel(new DiamondIcon(Color.black))); js4.setLabelTable(table); js4.setPaintLabels(true); js4.setSnapToTicks(true); Container c = f.getContentPane(); c.add(js1, BorderLayout.NORTH); c.add(js2, BorderLayout.SOUTH); c.add(js3, BorderLayout.WEST); c.add(js4, BorderLayout.EAST); f.setSize(300, 200); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JSlider Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSlider slider = new JSlider(); slider.setMinorTickSpacing(5);/*from w ww. j av a 2 s . com*/ slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setPaintTrack(false); slider.setPaintLabels(true); f.add(slider, BorderLayout.CENTER); f.setSize(300, 100); f.setVisible(true); }
From source file:fr.free.hd.servers.gui.FaceView.java
private JPanel createMouth() { JPanel panel = new JPanel(new GridLayout(3, 0)); final JSlider slider = new JSlider(); final JSlider sliderX = new JSlider(); final JSlider sliderY = new JSlider(); slider.setMinimum(0);//from w w w . j ava 2 s. c o m slider.setMaximum(1000); slider.setMajorTickSpacing(100); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setPaintTrack(true); sliderX.setMinimum(-1000); sliderX.setMaximum(1000); sliderX.setMajorTickSpacing(100); sliderX.setPaintLabels(true); sliderX.setPaintTicks(true); sliderX.setPaintTrack(true); sliderY.setMinimum(-1000); sliderY.setMaximum(1000); sliderY.setMajorTickSpacing(100); sliderY.setPaintLabels(true); sliderY.setPaintTicks(true); sliderY.setPaintTrack(true); sliderX.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { face.setMouthXPercent(sliderX.getValue()); updateLabel(); } }); sliderY.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { face.setMouthYPercent(sliderY.getValue()); updateLabel(); } }); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { face.setMouthRatio(slider.getValue()); updateLabel(); } }); panel.add(slider); panel.add(sliderX); panel.add(sliderY); return panel; }
From source file:fr.free.hd.servers.gui.FaceView.java
private JPanel createKind() { JPanel panel = new JPanel(new GridLayout(3, 0)); final JSlider sliderX = new JSlider(); final JSlider sliderY = new JSlider(); final JComboBox box = new JComboBox(HandKeyEnum.values()); sliderX.setMinimum(-1000);/*from ww w . j a va 2 s .c o m*/ sliderX.setMaximum(1000); sliderX.setMajorTickSpacing(100); sliderX.setPaintLabels(true); sliderX.setPaintTicks(true); sliderX.setPaintTrack(true); sliderY.setMinimum(-1000); sliderY.setMaximum(1000); sliderY.setMajorTickSpacing(100); sliderY.setPaintLabels(true); sliderY.setPaintTicks(true); sliderY.setPaintTrack(true); box.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { kind = (HandKeyEnum) e.getItem(); updateLabel(); } }); panel.add(box); sliderX.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (kind) { case HAND_KEY_2D: face.setAnchorX_2D(sliderX.getValue()); break; case HAND_KEY_2M: face.setAnchorX_2M(sliderX.getValue()); break; case HAND_KEY_1M: face.setAnchorX_1M(sliderX.getValue()); break; case HAND_KEY_2V: face.setAnchorX_2V(sliderX.getValue()); break; case HAND_KEY_3D: face.setAnchorX_3D(sliderX.getValue()); break; case HAND_KEY_3G: face.setAnchorX_3G(sliderX.getValue()); break; case HAND_KEY_4G: face.setAnchorX_4G(sliderX.getValue()); break; case HAND_KEY_5M: face.setAnchorX_5M(sliderX.getValue()); break; } updateLabel(); } }); sliderY.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (kind) { case HAND_KEY_2D: face.setAnchorY_2D(sliderY.getValue()); break; case HAND_KEY_2M: face.setAnchorY_2M(sliderY.getValue()); break; case HAND_KEY_1M: face.setAnchorY_1M(sliderY.getValue()); break; case HAND_KEY_2V: face.setAnchorY_2V(sliderY.getValue()); break; case HAND_KEY_3D: face.setAnchorY_3D(sliderY.getValue()); break; case HAND_KEY_3G: face.setAnchorY_3G(sliderY.getValue()); break; case HAND_KEY_4G: face.setAnchorY_4G(sliderY.getValue()); break; case HAND_KEY_5M: face.setAnchorY_5M(sliderY.getValue()); break; } updateLabel(); } }); panel.add(sliderX); panel.add(sliderY); return panel; }
From source file:SliderTest.java
public SliderTestFrame() { setTitle("SliderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); sliderPanel = new JPanel(); sliderPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // common listener for all sliders listener = new ChangeListener() { public void stateChanged(ChangeEvent event) { // update text field when the slider value changes JSlider source = (JSlider) event.getSource(); textField.setText("" + source.getValue()); }//from ww w . j a v a 2s.c o m }; // add a plain slider JSlider slider = new JSlider(); addSlider(slider, "Plain"); // add a slider with major and minor ticks slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Ticks"); // add a slider that snaps to ticks slider = new JSlider(); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Snap to ticks"); // add a slider with no track slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.setPaintTrack(false); addSlider(slider, "No track"); // add an inverted slider slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.setInverted(true); addSlider(slider, "Inverted"); // add a slider with numeric labels slider = new JSlider(); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Labels"); // add a slider with alphabetic labels slider = new JSlider(); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); Dictionary<Integer, Component> labelTable = new Hashtable<Integer, Component>(); labelTable.put(0, new JLabel("A")); labelTable.put(20, new JLabel("B")); labelTable.put(40, new JLabel("C")); labelTable.put(60, new JLabel("D")); labelTable.put(80, new JLabel("E")); labelTable.put(100, new JLabel("F")); slider.setLabelTable(labelTable); addSlider(slider, "Custom labels"); // add a slider with icon labels slider = new JSlider(); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setSnapToTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(20); labelTable = new Hashtable<Integer, Component>(); // add card images labelTable.put(0, new JLabel(new ImageIcon("nine.gif"))); labelTable.put(20, new JLabel(new ImageIcon("ten.gif"))); labelTable.put(40, new JLabel(new ImageIcon("jack.gif"))); labelTable.put(60, new JLabel(new ImageIcon("queen.gif"))); labelTable.put(80, new JLabel(new ImageIcon("king.gif"))); labelTable.put(100, new JLabel(new ImageIcon("ace.gif"))); slider.setLabelTable(labelTable); addSlider(slider, "Icon labels"); // add the text field that displays the slider value textField = new JTextField(); add(sliderPanel, BorderLayout.CENTER); add(textField, BorderLayout.SOUTH); }
From source file:fr.free.hd.servers.gui.FaceView.java
private JPanel createPosition() { JPanel panel = new JPanel(new GridLayout(5, 0)); final JSlider slider = new JSlider(); final JSlider sliderDegree = new JSlider(); final JSlider sliderX = new JSlider(); final JSlider sliderY = new JSlider(); slider.setMinimum(0);/* w ww . j a v a 2 s . c om*/ slider.setMaximum(1000); sliderX.setMinimum(-1000); sliderX.setMaximum(1000); sliderX.setMajorTickSpacing(100); sliderX.setPaintLabels(true); sliderX.setPaintTicks(true); sliderX.setPaintTrack(true); sliderY.setMinimum(-1000); sliderY.setMaximum(1000); sliderY.setMajorTickSpacing(100); sliderY.setPaintLabels(true); sliderY.setPaintTicks(true); sliderY.setPaintTrack(true); sliderDegree.setMinimum(0); sliderDegree.setMaximum(360); sliderDegree.setMajorTickSpacing(20); sliderDegree.setPaintLabels(true); sliderDegree.setPaintTicks(true); sliderDegree.setPaintTrack(true); final JComboBox box = new JComboBox(HandPositionEnum.values()); box.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { position = (HandPositionEnum) e.getItem(); updateLabel(); } }); panel.add(box); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheRatio(slider.getValue()); break; case HAND_POSITION_COTE: face.setCoteRatio(slider.getValue()); break; case HAND_POSITION_COU: face.setCouRatio(slider.getValue()); break; case HAND_POSITION_MENTON: face.setMentonRatio(slider.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteRatio(slider.getValue()); break; } updateLabel(); } }); sliderDegree.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheDegree(sliderDegree.getValue()); break; case HAND_POSITION_COTE: face.setCoteDegree(sliderDegree.getValue()); break; case HAND_POSITION_COU: face.setCouDegree(sliderDegree.getValue()); break; case HAND_POSITION_MENTON: face.setMentonDegree(sliderDegree.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteDegree(sliderDegree.getValue()); break; } updateLabel(); } }); sliderX.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheX(sliderX.getValue()); break; case HAND_POSITION_COTE: face.setCoteX(sliderX.getValue()); break; case HAND_POSITION_COU: face.setCouX(sliderX.getValue()); break; case HAND_POSITION_MENTON: face.setMentonX(sliderX.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteX(sliderX.getValue()); break; } updateLabel(); } }); sliderY.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { switch (position) { case HAND_POSITION_BOUCHE: face.setBoucheY(sliderY.getValue()); break; case HAND_POSITION_COTE: face.setCoteY(sliderY.getValue()); break; case HAND_POSITION_COU: face.setCouY(sliderY.getValue()); break; case HAND_POSITION_MENTON: face.setMentonY(sliderY.getValue()); break; case HAND_POSITION_PAUMETTE: face.setPaumetteY(sliderY.getValue()); break; } updateLabel(); } }); panel.add(slider); panel.add(sliderX); panel.add(sliderY); panel.add(sliderDegree); return panel; }