Example usage for javax.swing JSlider setLabelTable

List of usage examples for javax.swing JSlider setLabelTable

Introduction

In this page you can find the example usage for javax.swing JSlider setLabelTable.

Prototype

@BeanProperty(hidden = true, visualUpdate = true, description = "Specifies what labels will be drawn for any given value.")
@SuppressWarnings("rawtypes")
public void setLabelTable(Dictionary labels) 

Source Link

Document

Used to specify what label will be drawn at any given value.

Usage

From source file:SoundPlayer.java

void addMidiControls() {
    // Add a slider to control the tempo
    final JSlider tempo = new JSlider(50, 200);
    tempo.setValue((int) (sequencer.getTempoFactor() * 100));
    tempo.setBorder(new TitledBorder("Tempo Adjustment (%)"));
    java.util.Hashtable labels = new java.util.Hashtable();
    labels.put(new Integer(50), new JLabel("50%"));
    labels.put(new Integer(100), new JLabel("100%"));
    labels.put(new Integer(200), new JLabel("200%"));
    tempo.setLabelTable(labels);
    tempo.setPaintLabels(true);/* w  w  w . j a  v  a2 s  . co m*/
    // The event listener actually changes the tmpo
    tempo.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            sequencer.setTempoFactor(tempo.getValue() / 100.0f);
        }
    });

    this.add(tempo);

    // Create rows of solo and checkboxes for each track
    Track[] tracks = sequence.getTracks();
    for (int i = 0; i < tracks.length; i++) {
        final int tracknum = i;
        // Two checkboxes per track
        final JCheckBox solo = new JCheckBox("solo");
        final JCheckBox mute = new JCheckBox("mute");
        // The listeners solo or mute the track
        solo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sequencer.setTrackSolo(tracknum, solo.isSelected());
            }
        });
        mute.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sequencer.setTrackMute(tracknum, mute.isSelected());
            }
        });

        // Build up a row
        Box box = Box.createHorizontalBox();
        box.add(new JLabel("Track " + tracknum));
        box.add(Box.createHorizontalStrut(10));
        box.add(solo);
        box.add(Box.createHorizontalStrut(10));
        box.add(mute);
        box.add(Box.createHorizontalGlue());
        // And add it to this component
        this.add(box);
    }
}

From source file:SoundPlayer.java

JSlider createSlider(final FloatControl c) {
    if (c == null)
        return null;
    final JSlider s = new JSlider(0, 1000);
    final float min = c.getMinimum();
    final float max = c.getMaximum();
    final float width = max - min;
    float fval = c.getValue();
    s.setValue((int) ((fval - min) / width * 1000));

    java.util.Hashtable labels = new java.util.Hashtable(3);
    labels.put(new Integer(0), new JLabel(c.getMinLabel()));
    labels.put(new Integer(500), new JLabel(c.getMidLabel()));
    labels.put(new Integer(1000), new JLabel(c.getMaxLabel()));
    s.setLabelTable(labels);
    s.setPaintLabels(true);/*  w  ww. j  a  va 2 s  . c  om*/

    s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits()));

    s.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            int i = s.getValue();
            float f = min + (i * width / 1000.0f);
            c.setValue(f);
        }
    });
    return s;
}

From source file:components.SliderDemo2.java

public SliderDemo2() {
    super(new BorderLayout());

    delay = 1000 / FPS_INIT;//from  w w  w  . j a  va2 s  . c o m

    //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);
}

From source file:AtomPanel.java

private void commonInit() {
    //initial time series plots
    initJFreeChart();//from w  ww. ja v a 2  s.  com
    startFlag = false;

    //create control panel
    //        JPanel panel=new JPanel(new GridLayout(1,2));
    //add control buttons to control panel
    /*
    startButton=new JButton("Start");
    startButton.addActionListener(this);
    pauseButton=new JButton("Pause");
    pauseButton.addActionListener(this);
    stopButton=new JButton("Stop");
    stopButton.addActionListener(this);
    panel.add(startButton);
    panel.add(pauseButton);
    panel.add(stopButton);
    */
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    //Create the slider
    JSlider faRateSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, L_INIT);
    faRateSlider.setName("faRate");
    faRateSlider.addChangeListener(this);
    faRateSlider.setMajorTickSpacing(30);
    faRateSlider.setPaintTicks(true);

    //Create the label table
    Hashtable labelTable = new Hashtable();
    labelTable.put(new Integer(L_MIN), new JLabel("0.1%"));
    labelTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   False Alarm Rate"));
    labelTable.put(new Integer(L_MAX), new JLabel("1%"));
    faRateSlider.setLabelTable(labelTable);

    faRateSlider.setPaintLabels(true);
    panel.add(faRateSlider);
    // window size slider
    JSlider wdSzSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, WDL_INIT);
    wdSzSlider.setName("wdSz");
    wdSzSlider.addChangeListener(this);
    wdSzSlider.setMajorTickSpacing(30);
    wdSzSlider.setPaintTicks(true);

    //Create the label table
    Hashtable wdTable = new Hashtable();
    wdTable.put(new Integer(L_MIN), new JLabel("20"));
    wdTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   Window Size"));
    wdTable.put(new Integer(L_MAX), new JLabel("200"));
    wdSzSlider.setLabelTable(wdTable);

    wdSzSlider.setPaintLabels(true);
    panel.add(wdSzSlider);
    if (AtomUtils.PCAType.pcaTrack == this.pcaType) { // new: tracking delta bar
        JSlider deltaSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, L_INIT);
        deltaSlider.setName("delta");
        deltaSlider.addChangeListener(this);
        deltaSlider.setMajorTickSpacing(30);
        deltaSlider.setPaintTicks(true);

        //Create the label table
        labelTable = new Hashtable();
        labelTable.put(new Integer(L_MIN), new JLabel("0%"));
        labelTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   Tracking Threshold"));
        labelTable.put(new Integer(L_MAX), new JLabel("20%"));
        deltaSlider.setLabelTable(labelTable);

        deltaSlider.setPaintLabels(true);
        panel.add(deltaSlider);

        // tracking saving label
        trackSaveLabel = new JLabel();
        trackSaveLabel.setText("Saved/Total:0/0");
        panel.add(trackSaveLabel);
    }
    if (AtomUtils.PCAType.pcaTrackAdjust == this.pcaType) {
        JSlider devSlider = new JSlider(JSlider.HORIZONTAL, L_MIN, L_MAX, L_INIT);
        devSlider.setName("devbnd");
        devSlider.addChangeListener(this);
        devSlider.setMajorTickSpacing(30);
        devSlider.setPaintTicks(true);

        //Create the label table
        labelTable = new Hashtable();
        labelTable.put(new Integer(L_MIN), new JLabel("0%"));
        labelTable.put(new Integer((L_MIN + L_MAX) / 2), new JLabel("   Deviation Bound"));
        labelTable.put(new Integer(L_MAX), new JLabel("1%"));
        devSlider.setLabelTable(labelTable);

        devSlider.setPaintLabels(true);
        panel.add(devSlider);

        // tracking saving label
        trackSaveLabel = new JLabel();
        trackSaveLabel.setText("Saved/Total:0/0");
        panel.add(trackSaveLabel);
    }
    add(panel, BorderLayout.SOUTH);

}

From source file:com.imag.nespros.gui.plugin.GraphEditor.java

/**
 * create an instance of a simple graph with popup controls to create a
 * graph./*from  ww  w  .j  av  a2s. c om*/
 *
 */
private GraphEditor(Simulation s) {
    simu = s;
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex);
    }
    // create a simple graph for the demo
    graph = Topology.getInstance().getGraph();
    this.layout = new StaticLayout<Device, ComLink>(graph, new Transformer<Device, Point2D>() {
        @Override
        public Point2D transform(Device v) {
            Point2D p = new Point2D.Double(v.getX(), v.getY());
            return p;
        }
    }, new Dimension(600, 600));

    vv = new VisualizationViewer<Device, ComLink>(layout);
    vv.setBackground(Color.white);

    final Transformer<Device, String> vertexLabelTransformer = new Transformer<Device, String>() {
        @Override
        public String transform(Device d) {
            return d.getDeviceName();
        }
    };

    //vv.getRenderContext().setVertexLabelTransformer(MapTransformer.<Device, String>getInstance(
    //      LazyMap.<Device, String>decorate(new HashMap<Device, String>(), new ToStringLabeller<Device>())));
    vv.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<ComLink, String>() {
        @Override
        public String transform(ComLink link) {
            return (link.getID() + ", " + link.getLatency());
        }
    });
    //float dash[] = {0.1f};
    //final Stroke edgeStroke = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 1.0f);
    final Stroke edgeStroke = new BasicStroke(3.0f);
    final Transformer<ComLink, Stroke> edgeStrokeTransformer = new Transformer<ComLink, Stroke>() {
        @Override
        public Stroke transform(ComLink l) {
            return edgeStroke;
        }
    };
    Transformer<ComLink, Paint> edgePaint = new Transformer<ComLink, Paint>() {
        public Paint transform(ComLink l) {
            if (l.isDown()) {
                return Color.RED;
            } else {
                return Color.BLACK;
            }
        }
    };
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
    vv.getRenderContext().setVertexIconTransformer(new CustomVertexIconTransformer());
    vv.getRenderContext().setVertexShapeTransformer(new CustomVertexShapeTransformer());

    vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {

        @Override
        public void paint(Graphics grphcs) {

            for (Device d : Topology.getInstance().getGraph().getVertices()) {
                int size = d.getOperators().size();
                MyLayeredIcon icon = d.getIcon();
                //if(icon == null) continue;
                icon.removeAll();
                if (size > 0) {
                    // the vertex icon                        
                    // Let's create the annotation image to be added to icon..
                    BufferedImage image = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g = image.createGraphics();
                    g.setColor(Color.ORANGE);
                    g.fillOval(0, 0, 20, 20);
                    g.setColor(Color.BLACK);
                    g.drawString(size + "", 5, 13);
                    g.dispose();
                    ImageIcon img = new ImageIcon(image);
                    //Dimension id = new Dimension(icon.getIconWidth(), icon.getIconHeight());
                    //double x = vv.getModel().getGraphLayout().transform(d).getX();
                    //x -= (icon.getIconWidth() / 2);
                    //double y = vv.getModel().getGraphLayout().transform(d).getY();
                    //y -= (icon.getIconHeight() / 2);
                    //grphcs.drawImage(image, (int) Math.round(x), (int) Math.round(y), null);
                    icon.add(img);
                }
            }
        }

        @Override
        public boolean useTransform() {
            return false;
        }
    });

    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    Factory<Device> vertexFactory = DeviceFactory.getInstance();
    Factory<ComLink> edgeFactory = ComLinkFactory.getInstance();

    final EditingModalGraphMouse<Device, ComLink> graphMouse = new EditingModalGraphMouse<>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    // Trying out our new popup menu mouse plugin...
    PopupVertexEdgeMenuMousePlugin myPlugin = new PopupVertexEdgeMenuMousePlugin();
    // Add some popup menus for the edges and vertices to our mouse plugin.
    JPopupMenu edgeMenu = new MyMouseMenus.EdgeMenu(frame);
    JPopupMenu vertexMenu = new MyMouseMenus.VertexMenu(frame);
    myPlugin.setEdgePopup(edgeMenu);
    myPlugin.setVertexPopup(vertexMenu);
    graphMouse.remove(graphMouse.getPopupEditingPlugin()); // Removes the existing popup editing plugin

    graphMouse.add(myPlugin); // Add our new plugin to the mouse  
    // AnnotatingGraphMousePlugin<Device,ComLink> annotatingPlugin =
    //   new AnnotatingGraphMousePlugin<>(vv.getRenderContext());
    //graphMouse.add(annotatingPlugin);
    // the EditingGraphMouse will pass mouse event coordinates to the
    // vertexLocations function to set the locations of the vertices as
    // they are created
    //        graphMouse.setVertexLocations(vertexLocations);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);

    //final ImageAtEdgePainter<String, String> imageAtEdgePainter = 
    //  new ImageAtEdgePainter<String, String>(vv, edge, image);
    final ScalingControl scaler = new CrossoverScalingControl();
    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton help = new JButton("Help");
    help.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(vv, instructions);
        }
    });
    JButton deploy = new JButton("Deploy");
    deploy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // OPMapping algo here
            if (simu == null) {
                return;
            }
            GraphUtil<Device, ComLink> util = new GraphUtil<>();
            for (EventProducer p : simu.getProducers()) {
                if (!p.isMapped()) {
                    JOptionPane.showMessageDialog(frame,
                            "Cannot map operators. Please deploy the producer: " + p.getName());
                    return;
                }
            }
            for (EventConsumer c : simu.getConsumers()) {
                if (!c.isMapped()) {
                    JOptionPane.showMessageDialog(frame,
                            "Cannot map operators. Please deploy the consumer: " + c.getName());
                    return;
                }
                System.out.println("-- Operator placement algorithm Greedy: " + c.getName() + " --");
                Solution init = util.initialMapping(c.getGraph());
                System.out.println(c.getGraph() + "\nInitial Mapping: " + init);
                OperatorMapping mapper = new OperatorMapping();
                long T1, T2;
                System.out.println("--- OpMapping Algo Greedy --- ");
                T1 = System.currentTimeMillis();
                Solution solution = mapper.opMapping(c.getGraph(), Topology.getInstance().getGraph(), init);
                T2 = System.currentTimeMillis();
                System.out.println(solution);
                System.out.println("Solution founded in: " + (T2 - T1) + " ms");
            }
            //                Solution init = util.initialMapping(EPGraph.getInstance().getGraph());
            //                System.out.println("Initial Mapping: " + init);
            //                OperatorMapping mapper = new OperatorMapping();
            //                long T1, T2;
            //                System.out.println("--- OpMapping Algo Greedy --- ");
            //                T1 = System.currentTimeMillis();
            //                Solution solution = mapper.opMapping(EPGraph.getInstance().getGraph(),
            //                        Topology.getInstance().getGraph(), init);
            //                T2 = System.currentTimeMillis();
            //                System.out.println(solution);
            //                System.out.println("Solution founded in: " + (T2 - T1) + " ms");
            vv.repaint();
        }
    });
    JButton run = new JButton("Run");
    run.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // run the simulation here
            System.out.println("Setting the simulation...");
            for (EventConsumer c : simu.getConsumers()) {

                for (EPUnit op : c.getGraph().getVertices()) {
                    if (op.isMapped()) {
                        op.openIOchannels();
                    } else {
                        JOptionPane.showMessageDialog(frame, "Cannot run, undeployed operators founded.");
                        return;
                    }
                }
            }
            //ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
            System.out.println("Running the simulation...");
            //scheduledExecutorService.execute(runner);
            for (Device device : Topology.getInstance().getGraph().getVertices()) {
                if (!device.isAlive()) {
                    device.start();
                }
            }
            for (ComLink link : Topology.getInstance().getGraph().getEdges()) {
                if (!link.isAlive()) {
                    link.start();
                }
            }
            for (EventConsumer c : simu.getConsumers()) {
                for (EPUnit op : c.getGraph().getVertices()) {
                    if (op.isMapped() && op.getDevice() != null && !op.isAlive()) {
                        op.start();
                    }
                }
            }

        }
    });
    AnnotationControls<Device, ComLink> annotationControls = new AnnotationControls<Device, ComLink>(
            graphMouse.getAnnotatingPlugin());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 30, 0);
    slider.setMinorTickSpacing(5);
    slider.setMajorTickSpacing(30);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setLabelTable(slider.createStandardLabels(15));
    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider slider = (JSlider) e.getSource();
            if (!slider.getValueIsAdjusting()) {
                speedSimulation(slider.getValue());
            }
        }
    });
    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    controls.add(annotationControls.getAnnotationsToolBar());
    controls.add(slider);
    controls.add(deploy);
    controls.add(run);
    controls.add(help);
    content.add(controls, BorderLayout.SOUTH);
    /* Custom JPanels can be added here  */
    //
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //final GraphEditor demo = new GraphEditor();

}

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 w  w  w. jav  a  2 s  . c om
    };

    // 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.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JPanel getPriorityPanel(final ViewState state) {
    JPanel panel = new JPanel();
    panel.setBorder(new EtchedBorder());
    panel.setLayout(new BorderLayout());
    panel.add(new JLabel("Priority:  "), BorderLayout.WEST);
    final JLabel priorityLabel = new JLabel(String.valueOf(DEFAULT_PRIORITY));
    panel.add(priorityLabel, BorderLayout.CENTER);
    JSlider slider = new JSlider(0, 100, (int) 5 * 10);
    slider.setMajorTickSpacing(10);//w  ww  . j  a  v a 2s.  c o  m
    slider.setMinorTickSpacing(1);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setSnapToTicks(false);
    Format f = new DecimalFormat("0.0");
    Hashtable<Integer, JComponent> labels = new Hashtable<Integer, JComponent>();
    for (int i = 0; i <= 10; i += 2) {
        JLabel label = new JLabel(f.format(i));
        label.setFont(label.getFont().deriveFont(Font.PLAIN));
        labels.put(i * 10, label);
    }
    slider.setLabelTable(labels);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            double value = ((JSlider) e.getSource()).getValue() / 10.0;
            priorityLabel.setText(value + "");
            priorityLabel.revalidate();
            if (!((JSlider) e.getSource()).getValueIsAdjusting()) {
                // FIXME: deal with priorities
                DefaultPropView.this.notifyListeners();
            }
        }

    });

    panel.add(slider, BorderLayout.SOUTH);
    return panel;
}