Java Code Examples for javax.swing.JSlider#setPaintLabels()
The following examples show how to use
javax.swing.JSlider#setPaintLabels() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimulateControlPanel.java From VanetSim with GNU General Public License v3.0 | 7 votes |
/** * Creates a slider for zooming. * * @return a ready-to-use <code>JSlider</code> */ private JSlider getZoomSlider() { JSlider slider = new JSlider(-75, 212, 1); Hashtable<Integer,JLabel> ht = new Hashtable<Integer,JLabel>(); // the labels correspond to a exponential scale but internally the slider calculates only in a constant scale => need to convert in stateChanged()! ht.put(-75, new JLabel("3km")); //$NON-NLS-1$ ht.put(-20, new JLabel("1km")); //$NON-NLS-1$ ht.put(45, new JLabel("200m")); //$NON-NLS-1$ ht.put(96, new JLabel("100m")); //$NON-NLS-1$ ht.put(157, new JLabel("30m")); //$NON-NLS-1$ ht.put(212, new JLabel("10m")); //$NON-NLS-1$ slider.setLabelTable(ht); slider.setPaintLabels(true); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(40); //slider.setPaintTicks(true); slider.addChangeListener(this); return slider; }
Example 2
Source File: ContrastAdjustmentMode.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
private JSlider createSlider(JPanel panel, GridBagLayout gb, GridBagConstraints c, String title, Font font, int sliderRange, int start) { Utils.log2("createSlider range: " + sliderRange + ", start: " + start); JSlider s = new JSlider(JSlider.HORIZONTAL, 0, sliderRange, start); s.setPaintLabels(false); s.setPaintTicks(false); s.setBackground(Color.white); c.gridy++; c.insets = new Insets(2, 10, 0, 10); gb.setConstraints(s, c); panel.add(s); JLabel l = new JLabel(title); l.setBackground(Color.white); l.setFont(font); c.gridy++; c.insets = new Insets(0, 10, IJ.isMacOSX() ? 4 : 0, 0); JPanel p = new JPanel(); p.setBackground(Color.white); p.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); gb.setConstraints(p, c); p.add(l); panel.add(p); return s; }
Example 3
Source File: DoubleLabeledSlider.java From binnavi with Apache License 2.0 | 6 votes |
public DoubleLabeledSlider(final String leftText, final String rightText, final int min, final int max) { setLayout(new BorderLayout()); final JLabel leftLabel = new JLabel(leftText); m_slider = new JSlider(min, max); m_slider.setMinorTickSpacing(1); m_slider.setPaintTicks(true); m_slider.setPaintLabels(true); final JLabel rightLabel = new JLabel(rightText); add(leftLabel, BorderLayout.WEST); add(m_slider); add(rightLabel, BorderLayout.EAST); }
Example 4
Source File: FuzzerOptionsPanel.java From zap-extensions with Apache License 2.0 | 6 votes |
private static JSlider createDefaultFuzzDelayInMsSlider( int delayInMs, int maxDelayInMs, final JLabel currentValueFeedbackLabel) { final JSlider delaySlider = new JSlider(); delaySlider.setMinimum(0); delaySlider.setValue(delayInMs); delaySlider.setMaximum(maxDelayInMs); delaySlider.setMinorTickSpacing(25); delaySlider.setMajorTickSpacing(100); delaySlider.setPaintTicks(true); delaySlider.setPaintLabels(true); delaySlider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { currentValueFeedbackLabel.setText(Integer.toString(delaySlider.getValue())); } }); return delaySlider; }
Example 5
Source File: FuzzOptionsPanel.java From zap-extensions with Apache License 2.0 | 6 votes |
private static JSlider createDefaultFuzzDelayInMsSlider( int defaultDelayInMs, int maxDelayInMs, final JLabel currentValueFeedbackLabel) { final JSlider delaySlider = new JSlider(); delaySlider.setMinimum(0); delaySlider.setValue(defaultDelayInMs); delaySlider.setMaximum(maxDelayInMs); delaySlider.setMinorTickSpacing(25); delaySlider.setMajorTickSpacing(100); delaySlider.setPaintTicks(true); delaySlider.setPaintLabels(true); delaySlider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { currentValueFeedbackLabel.setText(Integer.toString(delaySlider.getValue())); } }); return delaySlider; }
Example 6
Source File: GUIWithSmartClock.java From txtUML with Eclipse Public License 1.0 | 6 votes |
private JSlider createSlider() { slider = new JSlider(SwingConstants.VERTICAL, 0, 30, 0); slider.addChangeListener(e -> { if (!slider.getValueIsAdjusting()) { model.changeTime(slider.getValue()); } }); slider.setMajorTickSpacing(5); slider.setMinorTickSpacing(1); slider.createStandardLabels(10); slider.setPaintTicks(true); slider.setPaintLabels(true); return slider; }
Example 7
Source File: TimeSeriesPlayerForm.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private JSlider createSpeedSlider() { final JSlider speedSlider = new JSlider(1, 10); speedSlider.setToolTipText("Choose the playing speed"); speedSlider.setSnapToTicks(true); speedSlider.setPaintTrack(true); speedSlider.setPaintTicks(true); speedSlider.setPaintLabels(true); speedSlider.setValue(6); speedSlider.setPreferredSize(new Dimension(80, speedSlider.getPreferredSize().height)); speedSlider.addChangeListener(e -> { timerDelay = calculateTimerDelay(); timer.setDelay(timerDelay); updateSpeedUnit(); }); return speedSlider; }
Example 8
Source File: JComponentBuilders.java From netbeans with Apache License 2.0 | 5 votes |
protected void setupInstance(JSlider instance) { super.setupInstance(instance); instance.setPaintTicks(paintTicks); instance.setPaintTrack(paintTrack); instance.setPaintLabels(paintLabels); instance.setInverted(isInverted); if (sliderModel != null) instance.setModel(sliderModel.createInstance()); instance.setMajorTickSpacing(majorTickSpacing); instance.setMinorTickSpacing(minorTickSpacing); instance.setSnapToTicks(snapToTicks); }
Example 9
Source File: JComponentBuilders.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected void setupInstance(JSlider instance) { super.setupInstance(instance); instance.setPaintTicks(paintTicks); instance.setPaintTrack(paintTrack); instance.setPaintLabels(paintLabels); instance.setInverted(isInverted); if (sliderModel != null) instance.setModel(sliderModel.createInstance()); instance.setMajorTickSpacing(majorTickSpacing); instance.setMinorTickSpacing(minorTickSpacing); instance.setSnapToTicks(snapToTicks); }
Example 10
Source File: ZoomSliderPanel.java From mars-sim with GNU General Public License v3.0 | 5 votes |
private JSlider getControl() { JSlider slider = new JSlider(JSlider.HORIZONTAL, 50, 200, 100); slider.setMajorTickSpacing(50); slider.setMinorTickSpacing(10); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.addChangeListener(this); return slider; }
Example 11
Source File: FilterPanel.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
private JSlider createSlider(int min, int max, int tick) { JSlider slideFilterLength = new JSlider(JSlider.HORIZONTAL, min, max, tick); slideFilterLength.addChangeListener(this); //Turn on labels at major tick marks. slideFilterLength.setMajorTickSpacing(tick); //slideFilterLength.setMinorTickSpacing(64); slideFilterLength.setPaintTicks(true); slideFilterLength.setPaintLabels(true); //slideFilterLength.createStandardLabels(tick); slideFilterLength.setSnapToTicks(true); return slideFilterLength; }
Example 12
Source File: Slider.java From dctb-utfpr-2018-1 with Apache License 2.0 | 5 votes |
Slider() { // Cria componentes titulo = new JLabel("Desenvolvimento Aberto - JSlider"); valor = new JLabel(mostraValor); slider = new JSlider(JSlider.HORIZONTAL, sMin, sMax, sPos); botao = new JButton("Ok"); // Adiciona propriedades ao componentes slider.setMajorTickSpacing(10); slider.setMinorTickSpacing(1); slider.setPaintTicks(true); slider.setPaintLabels(true); botao.addActionListener(this); // Cria layout GridLayout layout = new GridLayout(0, 1, 5, 10); setLayout(layout); // Adiciona componentes no painel add(valor); add(slider); add(botao); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
Example 13
Source File: JavaMixer.java From Spark with Apache License 2.0 | 5 votes |
private JComponent createControlComponent(FloatControl control) { int orientation = isBalanceOrPan(control) ? JSlider.HORIZONTAL : JSlider.VERTICAL; BoundedRangeModel model = new JavaMixer.FloatControlBoundedRangeModel(control); JSlider slider = new JSlider(model); slider.setOrientation(orientation); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setSize(10, 50); return slider; }
Example 14
Source File: LoadSpeedSimulationPanel.java From blog with Apache License 2.0 | 5 votes |
public LoadSpeedSimulationPanel() { setLayout(null); loadPersonsSpeedModel.setMinimum(0); loadPersonsSpeedModel.setMaximum(MAX_LOAD_SPEED_MS); loadPersonsSpeedModel.setValue(INITIAL_LOAD_SPEED_MS); loadPersonsSpeedModel.setExtent(0); JSlider loadSpeedSlider = new JSlider(); loadSpeedSlider.setMinorTickSpacing(MIN_LOAD_SPEED_TICK_MS); loadSpeedSlider.setSnapToTicks(true); loadSpeedSlider.setPaintTicks(true); loadSpeedSlider.setPaintLabels(true); loadSpeedSlider.setBounds(161, 12, 429, 43); loadSpeedSlider.setModel(loadPersonsSpeedModel); add(loadSpeedSlider); JLabelTextComponent selectedLoadSpeed = new JLabelTextComponent(""); selectedLoadSpeed.setFont(new Font("Tahoma", Font.PLAIN, 12)); selectedLoadSpeed.setBounds(10, 38, 138, 14); add(selectedLoadSpeed); // adapt the jLabel to the Document model to support MVC. MessageFormat speedLabelFormat = new MessageFormat( SIMULATION_SPEED_FORMAT); Document loadSpeedDocument = selectedLoadSpeed.getDocument(); BoundedRangeModel2DocumentAdapter boundedRangeAdapter = new BoundedRangeModel2DocumentAdapter( loadSpeedDocument, speedLabelFormat); boundedRangeAdapter.bind(loadPersonsSpeedModel); JLabel label = new JLabel("Load Speed Simulation"); label.setFont(new Font("Tahoma", Font.PLAIN, 12)); label.setBounds(10, 11, 138, 14); add(label); setPreferredSize(new Dimension(600, 60)); }
Example 15
Source File: MainWindow.java From Creatures with GNU General Public License v2.0 | 4 votes |
private void initUI(WorldView view) { JPanel rightContainer = new JPanel(); rightContainer.setLayout(new BoxLayout(rightContainer, BoxLayout.PAGE_AXIS)); textLabel = new JLabel("Creatures"); textLabel.setAlignmentX(Component.LEFT_ALIGNMENT); speedLabel = new JLabel("Speed"); speedLabel.setAlignmentX(Component.LEFT_ALIGNMENT); speedSlider = new JSlider(0, 15, 1); speedSlider.setAlignmentX(Component.LEFT_ALIGNMENT); speedSlider.setMajorTickSpacing(5); speedSlider.setMinorTickSpacing(1); speedSlider.setSnapToTicks(true); speedSlider.setPaintLabels(true); speedSlider.setPaintTicks(true); speedSlider.addChangeListener(this); JPanel maxFoodContainer = new JPanel(); maxFoodContainer.setLayout(new FlowLayout(FlowLayout.LEFT)); maxFoodContainer.setAlignmentX(Component.LEFT_ALIGNMENT); maxFoodLabel = new JLabel("Max Food"); SpinnerModel maxFoodSpinnerModel = new SpinnerNumberModel(WorldModel.maxFoodAmount, 0, 100000, 1); maxFoodSpinner = new JSpinner(maxFoodSpinnerModel); maxFoodSpinner.setEditor(new JSpinner.NumberEditor(maxFoodSpinner, "#")); maxFoodSpinner.addChangeListener(this); maxFoodContainer.add(maxFoodLabel); maxFoodContainer.add(maxFoodSpinner); rightContainer.add(textLabel); rightContainer.add(Box.createVerticalStrut(10)); rightContainer.add(speedLabel); rightContainer.add(speedSlider); rightContainer.add(maxFoodContainer); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, view, rightContainer); splitPane.setResizeWeight(0.8); add(splitPane); menuBar = new JMenuBar(); fileMenu = new JMenu("File"); exportStatisticsItem = new JMenuItem("Export Statistics"); exportStatisticsItem.addActionListener(this); closeItem = new JMenuItem("Close"); closeItem.addActionListener(this); fileMenu.add(exportStatisticsItem); fileMenu.addSeparator(); fileMenu.add(closeItem); worldMenu = new JMenu("Creation"); createWorldItem = new JMenuItem("Create World"); createWorldItem.addActionListener(this); worldMenu.add(createWorldItem); worldMenu.addSeparator(); createCreatureItem = new JMenuItem("Create Creature"); createCreatureItem.addActionListener(this); worldMenu.add(createCreatureItem); createCreaturesItem = new JMenuItem("Create Creatures"); createCreaturesItem.addActionListener(this); worldMenu.add(createCreaturesItem); statisticsMenu = new JMenu("Statistics"); showStatisticsItem = new JMenuItem("Show Statistics"); showStatisticsItem.addActionListener(this); statisticsMenu.add(showStatisticsItem); menuBar.add(fileMenu); menuBar.add(worldMenu); menuBar.add(statisticsMenu); setJMenuBar(menuBar); }
Example 16
Source File: ColorPick.java From Spark with Apache License 2.0 | 4 votes |
/** * Creates a Colorpicker with initial values 0,0,0,0 * * @param opacity * , true if Opacity Slider should be visible */ public ColorPick(boolean opacity) { this.setLayout(new GridBagLayout()); JLabel red = new JLabel(Res.getString("lookandfeel.color.red")); JLabel green = new JLabel(Res.getString("lookandfeel.color.green")); JLabel blue = new JLabel(Res.getString("lookandfeel.color.blue")); JLabel opaq = new JLabel(Res.getString("lookandfeel.color.opacity")); JSlider redslider = new JSlider(0,255); JSlider greenslider = new JSlider(0,255); JSlider blueslider = new JSlider(0,255); JSlider opaqslider = new JSlider(0,255); _sliderarray = new JSlider[4]; _sliderarray[0] = redslider; _sliderarray[1] = greenslider; _sliderarray[2] = blueslider; _sliderarray[3] = opaqslider; for(JSlider s : _sliderarray) { s.addChangeListener(this); s.setMajorTickSpacing(256/3); s.setMinorTickSpacing(0); s.setPaintTicks(true); s.setPaintLabels(true); } _preview = new JLabel(" "); _preview.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); _preview.setOpaque(true); this.add(red,new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); this.add(redslider,new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); this.add(green,new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); this.add(greenslider,new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); this.add(blue,new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); this.add(blueslider,new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); if(opacity) { this.add(opaq,new GridBagConstraints(0, 3, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); this.add(opaqslider,new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); } this.add(_preview,new GridBagConstraints(2, 0, 1, 4, 0.1, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0)); }
Example 17
Source File: MetadataPlotPanel.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private JPanel createSettingsPanel(BindingContext bindingContext) { final JLabel datasetLabel = new JLabel("Dataset: "); final JComboBox<MetadataElement> datasetBox = new JComboBox<>(); datasetBox.setRenderer(new ProductNodeListCellRenderer()); JLabel recordLabel = new JLabel("Record: "); recordValueField = new JTextField(7); recordSlider = new JSlider(SwingConstants.HORIZONTAL, 1, 1, 1); recordSlider.setPaintTrack(true); recordSlider.setPaintTicks(true); recordSlider.setPaintLabels(true); configureSilderLabels(recordSlider); JLabel numRecordsLabel = new JLabel("Records / Plot: "); numRecSpinnerModel = new SpinnerNumberModel(1, 1, 1, 1); JSpinner numRecordsSpinner = new JSpinner(numRecSpinnerModel); numRecordsSpinner.setEditor(new JSpinner.NumberEditor(numRecordsSpinner, "#")); final JLabel xFieldLabel = new JLabel("X Field: "); final JComboBox<MetadataAttribute> xFieldBox = new JComboBox<>(); xFieldBox.setRenderer(new ProductNodeListCellRenderer()); final JLabel y1FieldLabel = new JLabel("Y Field: "); final JComboBox<MetadataAttribute> y1FieldBox = new JComboBox<>(); y1FieldBox.setRenderer(new ProductNodeListCellRenderer()); final JLabel y2FieldLabel = new JLabel("Y2 Field: "); final JComboBox<MetadataAttribute> y2FieldBox = new JComboBox<>(); y2FieldBox.setRenderer(new ProductNodeListCellRenderer()); bindingContext.bind(PROP_NAME_METADATA_ELEMENT, datasetBox); bindingContext.bind(PROP_NAME_RECORD_START_INDEX, recordValueField); bindingContext.bind(PROP_NAME_RECORD_START_INDEX, new SliderAdapter(recordSlider)); bindingContext.bind(PROP_NAME_RECORDS_PER_PLOT, numRecordsSpinner); bindingContext.bind(PROP_NAME_FIELD_X, xFieldBox); bindingContext.bind(PROP_NAME_FIELD_Y1, y1FieldBox); bindingContext.bind(PROP_NAME_FIELD_Y2, y2FieldBox); TableLayout layout = new TableLayout(3); JPanel plotSettingsPanel = new JPanel(layout); layout.setTableWeightX(0.0); layout.setTableAnchor(TableLayout.Anchor.NORTHWEST); layout.setTableFill(TableLayout.Fill.HORIZONTAL); layout.setTablePadding(4, 4); layout.setCellWeightX(0, 1, 1.0); layout.setCellColspan(0, 1, 2); plotSettingsPanel.add(datasetLabel); plotSettingsPanel.add(datasetBox); layout.setCellWeightX(1, 1, 0.2); layout.setCellWeightX(1, 2, 0.8); plotSettingsPanel.add(recordLabel); plotSettingsPanel.add(recordValueField); plotSettingsPanel.add(recordSlider); layout.setCellWeightX(2, 1, 1.0); layout.setCellColspan(2, 1, 2); plotSettingsPanel.add(numRecordsLabel); plotSettingsPanel.add(numRecordsSpinner); layout.setCellWeightX(3, 1, 1.0); layout.setCellColspan(3, 1, 2); plotSettingsPanel.add(xFieldLabel); plotSettingsPanel.add(xFieldBox); layout.setCellWeightX(4, 1, 1.0); layout.setCellColspan(4, 1, 2); plotSettingsPanel.add(y1FieldLabel); plotSettingsPanel.add(y1FieldBox); layout.setCellWeightX(5, 1, 1.0); layout.setCellColspan(5, 1, 2); plotSettingsPanel.add(y2FieldLabel); plotSettingsPanel.add(y2FieldBox); updateSettings(); updateUiState(); return plotSettingsPanel; }
Example 18
Source File: DeobfuscationDialog.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public DeobfuscationDialog() { setDefaultCloseOperation(HIDE_ON_CLOSE); setSize(new Dimension(330, 270)); setTitle(translate("dialog.title")); Container cp = getContentPane(); cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS)); codeProcessingLevel = new JSlider(JSlider.VERTICAL, 1, 3, 3); codeProcessingLevel.setMajorTickSpacing(1); codeProcessingLevel.setPaintTicks(true); codeProcessingLevel.setMinorTickSpacing(1); codeProcessingLevel.setSnapToTicks(true); JLabel lab1 = new JLabel(translate("deobfuscation.level")); //lab1.setBounds(30, 0, getWidth() - 60, 25); lab1.setAlignmentX(0.5f); cp.add(lab1); Hashtable<Integer, JLabel> labelTable = new Hashtable<>(); //labelTable.put(LEVEL_NONE, new JLabel("None")); labelTable.put(DeobfuscationLevel.LEVEL_REMOVE_DEAD_CODE.getLevel(), new JLabel(translate("deobfuscation.removedeadcode"))); labelTable.put(DeobfuscationLevel.LEVEL_REMOVE_TRAPS.getLevel(), new JLabel(translate("deobfuscation.removetraps"))); labelTable.put(DeobfuscationLevel.LEVEL_RESTORE_CONTROL_FLOW.getLevel(), new JLabel(translate("deobfuscation.restorecontrolflow"))); codeProcessingLevel.setLabelTable(labelTable); codeProcessingLevel.setPaintLabels(true); codeProcessingLevel.setAlignmentX(Component.CENTER_ALIGNMENT); //codeProcessingLevel.setSize(300, 200); //codeProcessingLevel.setBounds(30, 25, getWidth() - 60, 125); codeProcessingLevel.setAlignmentX(0.5f); add(codeProcessingLevel); //processAllCheckbox.setBounds(50, 150, getWidth() - 100, 25); processAllCheckbox.setAlignmentX(0.5f); add(processAllCheckbox); processAllCheckbox.setSelected(true); JButton cancelButton = new JButton(translate("button.cancel")); cancelButton.addActionListener(this::cancelButtonActionPerformed); JButton okButton = new JButton(translate("button.ok")); okButton.addActionListener(this::okButtonActionPerformed); JPanel buttonsPanel = new JPanel(new FlowLayout()); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); buttonsPanel.setAlignmentX(0.5f); cp.add(buttonsPanel); setModal(true); View.centerScreen(this); setIconImage(View.loadImage("deobfuscate16")); }
Example 19
Source File: Sliders.java From dctb-utfpr-2018-1 with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // Create and set up a frame window JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Slider with change listener"); frame.setSize(500, 500); frame.setLayout(new GridLayout(3, 1)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set the panel to add buttons JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); // Add status label to show the status of the slider JLabel status = new JLabel("Slide the slider and you can get its value", JLabel.CENTER); // Set the slider JSlider slider = new JSlider(); slider.setMinorTickSpacing(10); slider.setPaintTicks(true); // Set the labels to be painted on the slider slider.setPaintLabels(true); // Add positions label in the slider Hashtable<Integer, JLabel> position = new Hashtable<Integer, JLabel>(); position.put(0, new JLabel("0")); position.put(50, new JLabel("50")); position.put(100, new JLabel("100")); // Set the label to be drawn slider.setLabelTable(position); // Add change listener to the slider slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { status.setText("Value of the slider is: " + ((JSlider)e.getSource()).getValue()); } }); // Add the slider to the panel panel1.add(slider); // Set the window to be visible as the default to be false frame.add(panel1); frame.add(status); frame.add(panel2); frame.pack(); frame.setVisible(true); }