List of usage examples for javax.swing JSpinner JSpinner
public JSpinner(SpinnerModel model)
From source file:TextInputDemo.java
protected JComponent createEntryFields() { JPanel panel = new JPanel(new SpringLayout()); String[] labelStrings = { "Street address: ", "City: ", "State: ", "Zip code: " }; JLabel[] labels = new JLabel[labelStrings.length]; JComponent[] fields = new JComponent[labelStrings.length]; int fieldNum = 0; //Create the text field and set it up. streetField = new JTextField(); streetField.setColumns(20);//w w w . ja va2 s. c o m fields[fieldNum++] = streetField; cityField = new JTextField(); cityField.setColumns(20); fields[fieldNum++] = cityField; String[] stateStrings = getStateStrings(); stateSpinner = new JSpinner(new SpinnerListModel(stateStrings)); fields[fieldNum++] = stateSpinner; zipField = new JFormattedTextField(createFormatter("#####")); fields[fieldNum++] = zipField; //Associate label/field pairs, add everything, //and lay it out. for (int i = 0; i < labelStrings.length; i++) { labels[i] = new JLabel(labelStrings[i], JLabel.TRAILING); labels[i].setLabelFor(fields[i]); panel.add(labels[i]); panel.add(fields[i]); //Add listeners to each field. JTextField tf = null; if (fields[i] instanceof JSpinner) { tf = getTextField((JSpinner) fields[i]); } else { tf = (JTextField) fields[i]; } tf.addActionListener(this); tf.addFocusListener(this); } SpringUtilities.makeCompactGrid(panel, labelStrings.length, 2, GAP, GAP, //init x,y GAP, GAP / 2);//xpad, ypad return panel; }
From source file:es.emergya.ui.plugins.forms.FormGeneric.java
protected void addDate(Date fecha, String title, boolean editable) { rows++;// w w w.j a v a 2 s .c o m // TODO editable mid.add(new JLabel(i18n.getString(title), JLabel.RIGHT)); JPanel panel = new JPanel(); panel.setOpaque(false); JCalendarCombo calendar = new JCalendarCombo(); calendar.setName(title); calendar.setEditable(editable); calendar.setPreferredSize(new Dimension(300, 30)); calendar.setDate(fecha); panel.add(calendar); componentes.add(calendar); JSpinner res = new JSpinner(new SpinnerDateModel()); res.setName(title); res.setPreferredSize(new Dimension(60, 30)); res.setName(title); JSpinner.DateEditor startEditor = new JSpinner.DateEditor(res, "HH:mm:ss"); startEditor.setEnabled(editable); res.setEditor(startEditor); if (fecha != null) res.setValue(fecha); componentes.add(res); panel.add(res); mid.add(panel); for (int i = 3; i < cols; i++) mid.add(Box.createHorizontalGlue()); }
From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java
private JPanel createAccuracyPanel() { final JPanel accuracyPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); final JLabel label = new JLabel("Histogram accuracy:"); accuracyModel = new AccuracyModel(); final BindingContext bindingContext = new BindingContext( PropertyContainer.createObjectBacked(accuracyModel)); final SpinnerNumberModel accuracyNumberModel = new SpinnerNumberModel(accuracyModel.accuracy, 0, Util.MAX_ACCURACY, 1); final JSpinner accuracySpinner = new JSpinner(accuracyNumberModel); ((JSpinner.DefaultEditor) accuracySpinner.getEditor()).getTextField().setEditable(false); bindingContext.bind("accuracy", accuracySpinner); final JCheckBox checkBox = new JCheckBox("Auto accuracy"); bindingContext.bind("useAutoAccuracy", checkBox); final IntervalValidator rangeValidator = new IntervalValidator(new ValueRange(0, Util.MAX_ACCURACY)); final PropertyDescriptor accuracyDescriptor = bindingContext.getPropertySet().getDescriptor("accuracy"); accuracyDescriptor.setValidator(rangeValidator); checkBox.setSelected(accuracyModel.useAutoAccuracy); bindingContext.getPropertySet().getProperty("useAutoAccuracy") .addPropertyChangeListener(new PropertyChangeListener() { @Override/*from w w w .j av a 2 s.c om*/ public void propertyChange(PropertyChangeEvent evt) { label.setEnabled(!checkBox.isSelected()); accuracySpinner.setEnabled(!checkBox.isSelected()); if (checkBox.isSelected()) { bindingContext.getBinding("accuracy").setPropertyValue(3); } computePanel.updateEnablement(); } }); label.setEnabled(false); accuracySpinner.setEnabled(false); accuracySpinner.setToolTipText("Specify the number of histogram bins (#bins: 10^accuracy)."); accuracySpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { computePanel.updateEnablement(); } }); GridBagUtils.addToPanel(accuracyPanel, new TitledSeparator("Histogram accuracy"), gbc, "fill=HORIZONTAL, weightx=1.0,anchor=NORTH,gridwidth=2"); GridBagUtils.addToPanel(accuracyPanel, checkBox, gbc, "gridy=1,insets.left=5,insets.top=2"); GridBagUtils.addToPanel(accuracyPanel, label, gbc, "gridy=2, insets.left=26,weightx=0.0,fill=NONE,anchor=WEST,gridwidth=1"); GridBagUtils.addToPanel(accuracyPanel, accuracySpinner, gbc, "gridx=1,weightx=1.0,fill=HORIZONTAL,insets.right=5,insets.left=5"); return accuracyPanel; }
From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java
private JSpinner getTypeB_DensitySpinner() { if (typeB_densitySpinner == null) { typeB_densitySpinner = new JSpinner( new SpinnerNumberModel(TypeBEvaluationOptions.getDensity(), 0, 300, 10)); }//from w w w. ja va 2s . c o m return typeB_densitySpinner; }
From source file:com.diversityarrays.kdxplore.design.EntryFileImportDialog.java
public EntryFileImportDialog(Window owner, String title, File inputFile, Predicate<Role> entryHeadingFilter) { super(owner, title, ModalityType.APPLICATION_MODAL); this.entryHeadingFilter = entryHeadingFilter; setDefaultCloseOperation(DISPOSE_ON_CLOSE); setGlassPane(backgroundRunner.getBlockingPane()); useScrollBarOption.addActionListener(new ActionListener() { @Override/*from ww w. ja v a2s .c o m*/ public void actionPerformed(ActionEvent e) { updateDataPreviewScrolling(); } }); headingRoleTableModel = createHeadingRoleTableModel(); headingRoleTable = new HeadingRoleTable<>(headingRoleTableModel); headingTableScrollPane = new JScrollPane(headingRoleTable); GuiUtil.setVisibleRowCount(headingRoleTable, 10); JPanel roleAssignmentPanel = new JPanel(new BorderLayout()); roleAssignmentPanel.add(headingTableScrollPane, BorderLayout.CENTER); headingRoleTable.setTransferHandler(flth); headingRoleTableModel.addChangeListener(headingRoleChangeListener); GuiUtil.setVisibleRowCount(dataPreviewTable, 10); dataPreviewTable.setTransferHandler(flth); dataPreviewScrollPane.setTransferHandler(flth); updateDataPreviewScrolling(); dataPreviewScrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { // boolean useScrollBar = useScrollBarOption.isSelected(); GuiUtil.initialiseTableColumnWidths(dataPreviewTable, true); } }); Box top = Box.createHorizontalBox(); top.add(new JLabel("# rows to preview: ")); top.add(new JSpinner(previewRowCountSpinnerModel)); top.add(Box.createHorizontalGlue()); top.add(useScrollBarOption); JPanel dataPreviewPanel = new JPanel(new BorderLayout()); dataPreviewPanel.add(GuiUtil.createLabelSeparator("Data Preview", top), BorderLayout.NORTH); dataPreviewPanel.add(dataPreviewScrollPane, BorderLayout.CENTER); headingWarning.setForeground(Color.RED); JLabel instructions = new JLabel("<HTML>Please assign a <i>Role</i> for each of the headings in your data" + "<br>You must specify one as the <i>Entry Name</i>." + "<br>Click on one of the <i>Role</i> cells and select from the dropdown" + "<br>To assign multiple headings, select the rows for which you wish" + "<br>to set the <i>Role</i> then right-click and choose from the dropdown."); instructions.setHorizontalAlignment(JLabel.CENTER); instructions.setBackground(Toast.PALE_YELLOW); JScrollPane instScroll = new JScrollPane(instructions); instScroll.setBackground(Toast.PALE_YELLOW); normalEntryNameField.getDocument() .addDocumentListener(new DocumentChangeListener((e) -> updateAcceptButton())); normalEntryNameField.setText(TrialDesignPreferences.getInstance().getNormalEntryTypeName()); JPanel rolesPanel = new JPanel(); GBH gbh = new GBH(rolesPanel, 2, 2, 0, 0); int y = 0; gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Entry Type Name for non-Checks:"); gbh.add(1, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, normalEntryNameField); gbh.add(2, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, saveForFuture); ++y; gbh.add(0, y, 3, 1, GBH.BOTH, 2, 1, GBH.CENTER, roleAssignmentPanel); ++y; JSplitPane headingsAndInstructions = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, rolesPanel, instScroll); JPanel headingPanel = new JPanel(new BorderLayout()); headingPanel.add(GuiUtil.createLabelSeparator("Assign Roles for Headings"), BorderLayout.NORTH); headingPanel.add(headingsAndInstructions, BorderLayout.CENTER); headingPanel.add(headingWarning, BorderLayout.SOUTH); errorMessage.setEditable(false); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, dataPreviewPanel, headingPanel); splitPane.setResizeWeight(0.5); cardPanel.add(new JScrollPane(errorMessage), CARD_ERROR); cardPanel.add(splitPane, CARD_DATA); Box bot = Box.createHorizontalBox(); bot.add(Box.createHorizontalGlue()); bot.add(new JButton(cancelAction)); bot.add(new JButton(acceptAction)); acceptAction.setEnabled(false); Container cp = getContentPane(); cp.add(cardPanel, BorderLayout.CENTER); cp.add(bot, BorderLayout.SOUTH); pack(); sheetNamesComboBox.addActionListener(sheetNamesActionListener); Timer timer = new Timer(true); previewRowCountSpinnerModel.addChangeListener(new ChangeListener() { int nPreview; TimerTask timerTask = null; @Override public void stateChanged(ChangeEvent e) { nPreview = previewRowCountSpinnerModel.getNumber().intValue(); if (timerTask == null) { timerTask = new TimerTask() { int lastPreviewCount = nPreview; @Override public void run() { if (lastPreviewCount == nPreview) { System.err.println("Stable at " + lastPreviewCount); // No change, do it now cancel(); try { updateDataPreview(lastPreviewCount); } finally { timerTask = null; } } else { System.err.println("Changing from " + lastPreviewCount + " to " + nPreview); lastPreviewCount = nPreview; } } }; timer.scheduleAtFixedRate(timerTask, 500, 100); } } }); sheetNamesComboBox.setVisible(false); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { removeWindowListener(this); setFile(inputFile); } }); }
From source file:es.emergya.ui.gis.popups.GenericDialog.java
protected void addDate(Date fecha, String title, boolean editable) { rows++;//from w w w .j av a 2 s . c o m // TODO editable mid.add(new JLabel(i18n.getString(title), JLabel.RIGHT)); JPanel panel = new JPanel(); panel.setOpaque(false); JCalendarCombo calendar = new JCalendarCombo(); calendar.setEditable(editable); calendar.setPreferredSize(new Dimension(300, 30)); calendar.setDate(fecha); calendar.setName(title); componentes.add(calendar); panel.add(calendar); JSpinner res = new JSpinner(new SpinnerDateModel()); res.setName(title); res.setPreferredSize(new Dimension(60, 30)); JSpinner.DateEditor startEditor = new JSpinner.DateEditor(res, "HH:mm:ss"); startEditor.setEnabled(editable); res.setEditor(startEditor); componentes.add(res); if (fecha != null) res.setValue(fecha); panel.add(res); mid.add(panel); for (int i = 3; i < cols; i++) mid.add(Box.createHorizontalGlue()); }
From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java
private JSpinner getTypeB_CO2AbsoluteMinimumSpinner() { if (typeB_co2AbsoluteMinimumSpinner == null) { typeB_co2AbsoluteMinimumSpinner = new JSpinner( new SpinnerNumberModel(TypeBEvaluationOptions.getCo2AbsoluteDatasetMinimum(), Integer.MIN_VALUE, Integer.MAX_VALUE, 10)); typeB_co2AbsoluteMinimumSpinner.setEnabled(!TypeBEvaluationOptions.isCo2AbsoluteAutoscale()); }//from w ww .j a v a 2s.c om return typeB_co2AbsoluteMinimumSpinner; }
From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java
private JSpinner getTypeB_CO2AbsoluteMaximumSpinner() { if (typeB_co2AbsoluteMaximumSpinner == null) { typeB_co2AbsoluteMaximumSpinner = new JSpinner( new SpinnerNumberModel(TypeBEvaluationOptions.getCo2AbsoluteDatasetMaximum(), Integer.MIN_VALUE, Integer.MAX_VALUE, 10)); typeB_co2AbsoluteMaximumSpinner.setEnabled(!TypeBEvaluationOptions.isCo2AbsoluteAutoscale()); }/*w w w . j av a 2 s . co m*/ return typeB_co2AbsoluteMaximumSpinner; }
From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java
private JSpinner getTypeB_deltaRawMaximumSpinner() { if (typeB_deltaRawMaximumSpinner == null) { typeB_deltaRawMaximumSpinner = new JSpinner(new SpinnerNumberModel( TypeBEvaluationOptions.getDeltaRawDatasetMaximum(), Integer.MIN_VALUE, Integer.MAX_VALUE, 10)); typeB_deltaRawMaximumSpinner.setEnabled(!TypeBEvaluationOptions.isDeltaRawAutoscale()); }//from w ww. j av a 2s. com return typeB_deltaRawMaximumSpinner; }
From source file:org.gridchem.client.gui.charts.UsageChart.java
private JPanel createSelectionBar() { chartTypeListModel = new CyclingSpinnerListModel(ChartType.values()); chartTypeSpinner = new JSpinner(chartTypeListModel); JFormattedTextField ftf = ((JSpinner.DefaultEditor) chartTypeSpinner.getEditor()).getTextField(); ftf.setColumns(6); //specify more width than we need ftf.setHorizontalAlignment(JTextField.CENTER); ftf.setEditable(false);// www . ja v a2s . co m JLabel spinnerLabel = new JLabel("Chart Type"); spinnerLabel.setLabelFor(chartTypeSpinner); JPanel buttonPanel = new JPanel(); buttonPanel.add(spinnerLabel, BorderLayout.CENTER); buttonPanel.add(chartTypeSpinner, BorderLayout.LINE_END); return buttonPanel; }