Java Code Examples for javax.swing.JSlider#setSnapToTicks()
The following examples show how to use
javax.swing.JSlider#setSnapToTicks() .
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: 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 2
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 3
Source File: TimeSeriesPlayerForm.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private JSlider createTimeSlider() { final JSlider timeSlider = new JSlider(JSlider.HORIZONTAL, 0, 0, 0); timeSlider.setMajorTickSpacing(stepsPerTimespan); timeSlider.setMinorTickSpacing(1); timeSlider.setPaintTrack(true); timeSlider.setSnapToTicks(true); timeSlider.setPaintTicks(true); timeSlider.addChangeListener(e -> { final int index = timeSlider.getValue() / stepsPerTimespan; final List<Band> bandList = getBandList(currentView.getRaster().getName()); final String labelText = createSliderLabelText(bandList, index); dateLabel.setText("Date: " + labelText); }); timeSlider.setPreferredSize(new Dimension(320, 60)); return timeSlider; }
Example 4
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 5
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 6
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 7
Source File: MovieContainer.java From iBioSim with Apache License 2.0 | 5 votes |
/** * adds the toolbar at the bottom */ private void addPlayUI() { // Add the bottom menu bar movieToolbar = new JToolBar(); fileButton = makeToolButton("", "choose_simulation_file", "Choose Simulation", this); movieToolbar.add(fileButton); clearButton = makeToolButton("", "clearAppearances", "Clear Appearances", this); movieToolbar.add(clearButton); movieToolbar.addSeparator(); rewindButton = makeToolButton("movie" + File.separator + "rewind.png", "rewind", "Rewind", this); movieToolbar.add(rewindButton); singleStepButton = makeToolButton("movie" + File.separator + "single_step.png", "singlestep", "Single Step", this); movieToolbar.add(singleStepButton); playPauseButton = makeToolButton("movie" + File.separator + "play.png", "playpause", "Play", this); movieToolbar.add(playPauseButton); slider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0); slider.setSnapToTicks(true); movieToolbar.add(slider); movieToolbar.setFloatable(false); this.add(movieToolbar, BorderLayout.SOUTH); }
Example 8
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 9
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 10
Source File: SpaceSliderPanel.java From Open-Realms-of-Stars with GNU General Public License v2.0 | 4 votes |
/** * Create space slider panel with - and + buttons and label * @param actionMinus ActionCommand for minus button * @param actionPlus ActionCommand for plus button * @param iconName Icon name to show * @param text Text for label * @param minValue Minimum value in slider * @param maxValue Maximum value in slider * @param sliderValue slider value * @param actionSlider slider action command * @param listener Action Listener */ public SpaceSliderPanel(final String actionMinus, final String actionPlus, final String iconName, final String text, final int minValue, final int maxValue, final int sliderValue, final String actionSlider, final ActionListener listener) { super(); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); btnMinus = new IconButton(Icons.getIconByName(Icons.ICON_MINUS), Icons.getIconByName(Icons.ICON_MINUS_PRESSED), false, actionMinus, this); btnMinus.addActionListener(listener); this.add(Box.createRigidArea(new Dimension(5, 5))); this.add(btnMinus); SpaceGreyPanel panel = new SpaceGreyPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); label = new IconLabel(null, Icons.getIconByName(iconName), text); panel.add(label); slider = new JSlider(minValue, maxValue, sliderValue); slider.setMinorTickSpacing(1); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setBackground(GuiStatics.COLOR_GREYBLUE); slider.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE); slider.addKeyListener(null); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { if (e.getSource() instanceof JSlider) { JSlider slide = (JSlider) e.getSource(); if (slide.getValue() % slide.getMinorTickSpacing() == 0) { listener.actionPerformed(new ActionEvent(e, 0, actionSlider)); } } } }); panel.add(slider); this.add(panel); btnPlus = new IconButton(Icons.getIconByName(Icons.ICON_PLUS), Icons.getIconByName(Icons.ICON_PLUS_PRESSED), false, actionPlus, this); btnPlus.addActionListener(listener); this.add(btnPlus); this.add(Box.createRigidArea(new Dimension(5, 5))); }
Example 11
Source File: ResearchTechPanel.java From Open-Realms-of-Stars with GNU General Public License v2.0 | 4 votes |
/** * Create Research Tech panel with - and + buttons and up arrow to * upgrade tech level. * @param actionMinus ActionCommand for minus button * @param actionPlus ActionCommand for plus button * @param iconName Icon name to show * @param text Text for tech focus label * @param text2 Text for tech level label * @param actionUpgrade ActionCommand for upgrade button * @param sliderValue slider value * @param actionSlider slider action command * @param listener Action Listener */ public ResearchTechPanel(final String actionMinus, final String actionPlus, final String iconName, final String text, final String text2, final String actionUpgrade, final int sliderValue, final String actionSlider, final ActionListener listener) { super(); this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); btnMinus = new IconButton(Icons.getIconByName(Icons.ICON_MINUS), Icons.getIconByName(Icons.ICON_MINUS_PRESSED), false, actionMinus, this); btnMinus.addActionListener(listener); this.add(Box.createRigidArea(new Dimension(5, 5))); this.add(btnMinus); SpaceGreyPanel panel = new SpaceGreyPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); label = new IconLabel(null, Icons.getIconByName(iconName), text); panel.add(label); slider = new JSlider(0, 100, sliderValue); slider.setMinorTickSpacing(4); slider.setMajorTickSpacing(20); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setBackground(GuiStatics.COLOR_GREYBLUE); slider.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE); slider.addKeyListener(null); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent e) { if (e.getSource() instanceof JSlider) { JSlider slide = (JSlider) e.getSource(); if (slide.getValue() % 4 == 0) { listener.actionPerformed(new ActionEvent(e, 0, actionSlider)); } } } }); panel.add(slider); lvlLabel = new IconLabel(null, Icons.getIconByName(Icons.ICON_EMPTY), text2); panel.add(lvlLabel); this.add(panel); btnUpgrade = new IconButton(Icons.getIconByName(Icons.ICON_ARROWUP), Icons.getIconByName(Icons.ICON_ARROWUP_PRESSED), false, actionUpgrade, this); btnUpgrade.setDisabledImage( Icons.getIconByName(Icons.ICON_ARROWUP_DISABLED).getIcon()); btnUpgrade.addActionListener(listener); btnUpgrade.setEnabled(false); this.add(btnUpgrade); btnPlus = new IconButton(Icons.getIconByName(Icons.ICON_PLUS), Icons.getIconByName(Icons.ICON_PLUS_PRESSED), false, actionPlus, this); btnPlus.addActionListener(listener); this.add(btnPlus); this.add(Box.createRigidArea(new Dimension(5, 5))); }
Example 12
Source File: GameToolbar.java From SproutLife with MIT License | 4 votes |
/** * Create the panel. */ public void buildPanel() { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); horizontalStrut = Box.createHorizontalStrut(20); add(horizontalStrut); JLabel lblZoom = new JLabel("Zoom"); add(lblZoom); //lblZoom.setMinimumSize(new Dimension(100, 14)); zoomSlider = new JSlider(); zoomSlider.setPreferredSize(new Dimension(100, 29)); add(zoomSlider); zoomSlider.setMinorTickSpacing(1); zoomSlider.setMinimum(-5); zoomSlider.setValue(-2); zoomSlider.setMaximum(5); JLabel speedLabel = new JLabel("Speed"); add(speedLabel); speedSlider = new JSlider(); speedSlider.setPreferredSize(new Dimension(100, 29)); speedSlider.setSnapToTicks(true); add(speedSlider); speedSlider.setMinimum(-5); speedSlider.setMaximum(4); speedSlider.setValue(-2); gifStopRecordingButton = new JButton("GIF - Stop Rec."); gifStopRecordingButton.setVisible(false); add(gifStopRecordingButton); startPauseButton = new JButton("Start"); add(startPauseButton); startPauseButton.setMaximumSize(new Dimension(200, 23)); startPauseButton.setPreferredSize(new Dimension(80, 29)); stepButton = new JButton("Step"); stepButton.setPreferredSize(new Dimension(80, 29)); add(stepButton); resetButton = new JButton("Reset"); resetButton.setPreferredSize(new Dimension(80, 29)); add(resetButton); horizontalStrut_1 = Box.createHorizontalStrut(20); add(horizontalStrut_1); }
Example 13
Source File: AmountPanel.java From testing-cin with MIT License | 4 votes |
/** * Constructor. */ public AmountPanel() { setBackground(UIConstants.TABLE_COLOR); sliderAmounts = new HashMap<Integer, Integer>(); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); amountSlider = new JSlider(); amountSlider.setBackground(UIConstants.TABLE_COLOR); amountSlider.setMajorTickSpacing(1); amountSlider.setMinorTickSpacing(1); amountSlider.setPaintTicks(true); amountSlider.setSnapToTicks(true); amountSlider.addChangeListener(this); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(0, 0, 0, 5); add(amountSlider, gbc); amountLabel = new JLabel(" "); amountLabel.setForeground(UIConstants.TEXT_COLOR); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 2; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(5, 0, 5, 0); add(amountLabel, gbc); betRaiseButton = new JButton("Bet"); betRaiseButton.addActionListener(this); gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(0, 0, 0, 0); add(betRaiseButton, gbc); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); gbc.gridx = 1; gbc.gridy = 2; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(0, 0, 0, 0); add(cancelButton, gbc); }
Example 14
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 15
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")); }