Java Code Examples for javax.swing.JSlider#setLabelTable()
The following examples show how to use
javax.swing.JSlider#setLabelTable() .
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: RangeOptionUI.java From freecol with GNU General Public License v2.0 | 6 votes |
/** * Creates a new {@code RangeOptionUI} for the given * {@code RangeOption}. * * @param option The {@code RangeOption} to make a user interface for * @param editable boolean whether user can modify the setting */ public RangeOptionUI(final RangeOption option, boolean editable) { super(option, editable); JSlider slider = getComponent(); slider.setModel(new DefaultBoundedRangeModel(option.getValueRank(), 0, 0, option.getItemValues().size()-1)); Hashtable<Integer, JComponent> labels = new Hashtable<>(); int index = 0; for (String string : option.getItemValues().values()) { if (option.localizeLabels()) { labels.put(index, Utility.localizedLabel(string)); } else { labels.put(index, new JLabel(string)); } index++; } slider.setLabelTable(labels); slider.setValue(option.getValueRank()); slider.setMajorTickSpacing(1); slider.setSnapToTicks(true); }
Example 3
Source File: PercentageOptionUI.java From freecol with GNU General Public License v2.0 | 6 votes |
/** * Creates a new {@code PercentageOptionUI} for the given * {@code PercentageOption}. * * @param option The {@code PercentageOption} to make a user * interface for. * @param editable boolean whether user can modify the setting */ public PercentageOptionUI(final PercentageOption option, boolean editable) { super(option, editable); JSlider slider = getComponent(); slider.setModel(new DefaultBoundedRangeModel(option.getValue(), 0, 0, 100)); Hashtable<Integer, JComponent> labels = new Hashtable<>(); labels.put(0, new JLabel("0 %")); labels.put(25, new JLabel("25 %")); labels.put(50, new JLabel("50 %")); labels.put(75, new JLabel("75 %")); labels.put(100, new JLabel("100 %")); slider.setLabelTable(labels); slider.setValue(option.getValue()); slider.setMajorTickSpacing(5); slider.setSnapToTicks(false); }
Example 4
Source File: ChartPanel.java From javamelody with Apache License 2.0 | 6 votes |
private JSlider createSlider() { final JSlider slider = new JSlider(); slider.setOpaque(false); slider.setMinimum(10); slider.setMaximum(200); slider.setValue(100); slider.setLabelTable(slider.createStandardLabels(50)); slider.setMajorTickSpacing(100); slider.setMinorTickSpacing(10); slider.setExtent(20); // slider.setPaintLabels(true); // slider.setPaintTicks(true); // slider.setSnapToTicks(true); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { final int value = slider.getValue(); refreshZoom(value); } }); return slider; }
Example 5
Source File: MetadataPlotPanel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void configureSilderLabels(JSlider recordSlider) { Hashtable<Integer, JLabel> labelTable = new Hashtable<>(); JLabel minLabel = new JLabel(String.valueOf(recordSlider.getMinimum())); labelTable.put(recordSlider.getMinimum(), minLabel); JLabel maxLabel = new JLabel(String.valueOf(recordSlider.getMaximum())); labelTable.put(recordSlider.getMaximum(), maxLabel); recordSlider.setLabelTable(labelTable); }
Example 6
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); }
Example 7
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")); }