List of usage examples for javax.swing JSlider setPaintTicks
@BeanProperty(visualUpdate = true, description = "If true tick marks are painted on the slider.") public void setPaintTicks(boolean b)
From source file:ArcApp.java
public JSlider setSlider(int min, int max, int init, int mjrTkSp, int mnrTkSp) { JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, init); slider.setPaintTicks(true); slider.setMajorTickSpacing(mjrTkSp); slider.setMinorTickSpacing(mnrTkSp); slider.setPaintLabels(true);// ww w .j av a 2 s . co m slider.addChangeListener(new SliderListener()); return slider; }
From source file:Main.java
public Main() { Container content = getContentPane(); content.setBackground(Color.white); JSlider slider1 = new JSlider(); slider1.setBorder(BorderFactory.createTitledBorder("JSlider without Tick Marks")); content.add(slider1, BorderLayout.NORTH); JSlider slider2 = new JSlider(); slider2.setBorder(BorderFactory.createTitledBorder("JSlider with Tick Marks")); slider2.setMajorTickSpacing(20);//from w ww . j a va 2s. c om slider2.setMinorTickSpacing(5); slider2.setPaintTicks(true); content.add(slider2, BorderLayout.CENTER); JSlider slider3 = new JSlider(); slider3.setBorder(BorderFactory.createTitledBorder("JSlider with Tick Marks & Labels")); slider3.setMajorTickSpacing(20); slider3.setMinorTickSpacing(5); slider3.setPaintTicks(true); slider3.setPaintLabels(true); content.add(slider3, BorderLayout.SOUTH); setSize(300, 300); setVisible(true); }
From source file:House.java
public JSlider setSlider(JPanel panel, int orientation, int minimumValue, int maximumValue, int initValue, int majorTickSpacing, int minorTickSpacing) { JSlider slider = new JSlider(orientation, minimumValue, maximumValue, initValue); slider.setPaintTicks(true); slider.setMajorTickSpacing(majorTickSpacing); slider.setMinorTickSpacing(minorTickSpacing); slider.setPaintLabels(true);/*from www. j a v a 2 s . co m*/ slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider tempSlider = (JSlider) e.getSource(); if (tempSlider.equals(sliderTransX)) { transX = sliderTransX.getValue() - 150.0; canvas.repaint(); } else if (tempSlider.equals(sliderTransY)) { transY = sliderTransY.getValue() - 150.0; canvas.repaint(); } else if (tempSlider.equals(sliderRotateTheta)) { rotateTheta = sliderRotateTheta.getValue() * Math.PI / 180; canvas.repaint(); } else if (tempSlider.equals(sliderRotateX)) { rotateX = sliderRotateX.getValue(); canvas.repaint(); } else if (tempSlider.equals(sliderRotateY)) { rotateY = sliderRotateY.getValue(); canvas.repaint(); } else if (tempSlider.equals(sliderScaleX)) { if (sliderScaleX.getValue() != 0.0) { scaleX = sliderScaleX.getValue() / 100.0; canvas.repaint(); } } else if (tempSlider.equals(sliderScaleY)) { if (sliderScaleY.getValue() != 0.0) { scaleY = sliderScaleY.getValue() / 100.0; canvas.repaint(); } } } }); panel.add(slider); return slider; }
From source file:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);// w w w . ja v a 2 s .com JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:WeatherWizard.java
public void initComponents() { setLayout(new BorderLayout()); JPanel p = new JPanel(); p.add(new JLabel("Temperature:")); JSlider tempSlider = new JSlider(20, 100, 65); tempSlider.setMinorTickSpacing(5);/*from w w w . j a v a 2 s.com*/ tempSlider.setMajorTickSpacing(20); tempSlider.setPaintTicks(true); tempSlider.setPaintLabels(true); tempSlider.addChangeListener(this); p.add(tempSlider); add("North", p); painter = new WeatherPainter(); painter.sun = loadImage("sun"); painter.cloud = loadImage("cloud"); painter.rain = loadImage("rain"); painter.snow = loadImage("snow"); painter.setTemperature(65); p.add("Center", painter); }
From source file:AlphaCompositeDemo.java
public AlphaCompositeDemo() { super();//from ww w. j av a2 s . com Container container = getContentPane(); canvas = new MyCanvas(); container.add(canvas); rulesBox = new JComboBox(rulesLabels); rulesBox.setSelectedIndex(0); rulesBox.setAlignmentX(Component.LEFT_ALIGNMENT); rulesBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); canvas.compositeRule = rules[cb.getSelectedIndex()]; canvas.repaint(); } }); slider.setPaintTicks(true); slider.setMajorTickSpacing(25); slider.setMinorTickSpacing(25); slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); canvas.alphaValue = (float) slider.getValue() / 100; canvas.repaint(); } }); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 3)); panel.add(rulesBox); panel.add(new JLabel("Alpha Adjustment x E-2: ", JLabel.RIGHT)); panel.add(slider); container.add(panel, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(500, 300); setVisible(true); }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);//from w w w. j av a2 s .c o m JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); // Setting the Slider sets that font into the textfield. stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
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()); }/* ww w .j av a 2 s .co 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:org.csml.tommo.sugar.modules.heatmap.MixedHeatmapDialog.java
private JSlider createMixParameterSlider() { JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, (int) (mixOperation.getParameter() * 100.0)); slider.setMajorTickSpacing(10);// w w w . ja va 2 s.c om slider.setSnapToTicks(true); slider.setPaintTicks(true); // slider.setPaintLabels(true); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSlider source = (JSlider) event.getSource(); if (!source.getValueIsAdjusting()) { double param = (double) source.getValue() / (double) 100.0; updateMixParameter(param); } } }); return slider; }
From source file:components.SliderDemo2.java
public SliderDemo2() { super(new BorderLayout()); delay = 1000 / FPS_INIT;/*from ww w.j a v a2s . c om*/ //Create the slider. JSlider framesPerSecond = new JSlider(JSlider.VERTICAL, FPS_MIN, FPS_MAX, FPS_INIT); framesPerSecond.addChangeListener(this); framesPerSecond.setMajorTickSpacing(10); framesPerSecond.setPaintTicks(true); //Create the label table. Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); //PENDING: could use images, but we don't have any good ones. labelTable.put(new Integer(0), new JLabel("Stop")); //new JLabel(createImageIcon("images/stop.gif")) ); labelTable.put(new Integer(FPS_MAX / 10), new JLabel("Slow")); //new JLabel(createImageIcon("images/slow.gif")) ); labelTable.put(new Integer(FPS_MAX), new JLabel("Fast")); //new JLabel(createImageIcon("images/fast.gif")) ); framesPerSecond.setLabelTable(labelTable); framesPerSecond.setPaintLabels(true); framesPerSecond.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); //Create the label that displays the animation. picture = new JLabel(); picture.setHorizontalAlignment(JLabel.CENTER); picture.setAlignmentX(Component.CENTER_ALIGNMENT); picture.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(10, 10, 10, 10))); updatePicture(0); //display first frame //Put everything together. add(framesPerSecond, BorderLayout.LINE_START); add(picture, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); //Set up a timer that calls this object's action handler. timer = new Timer(delay, this); timer.setInitialDelay(delay * 7); //We pause animation twice per cycle //by restarting the timer timer.setCoalesce(true); }