List of usage examples for javax.swing JSpinner setEditor
@BeanProperty(visualUpdate = true, description = "JComponent that displays the current value of the model") public void setEditor(JComponent editor)
JComponent
that displays the current value of the SpinnerModel
. From source file:components.SpinnerDemo3.java
public SpinnerDemo3(boolean cycleMonths) { super(new SpringLayout()); String[] labels = { "Month: ", "Year: ", "Another Date: " }; int numPairs = labels.length; calendar = Calendar.getInstance(); JFormattedTextField ftf = null; //Add the first label-spinner pair. String[] monthStrings = getMonthStrings(); //get month names SpinnerListModel monthModel = null; if (cycleMonths) { //use custom model monthModel = new CyclingSpinnerListModel(monthStrings); } else { //use standard model monthModel = new SpinnerListModel(monthStrings); }//from w ww .j ava 2 s . c o m JSpinner spinner = addLabeledSpinner(this, labels[0], monthModel); //Tweak the spinner's formatted text field. ftf = getTextField(spinner); if (ftf != null) { ftf.setColumns(8); //specify more width than we need ftf.setHorizontalAlignment(JTextField.RIGHT); } //Add second label-spinner pair. int currentYear = calendar.get(Calendar.YEAR); SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value currentYear - 100, //min currentYear + 100, //max 1); //step //If we're cycling, hook this model up to the month model. if (monthModel instanceof CyclingSpinnerListModel) { ((CyclingSpinnerListModel) monthModel).setLinkedModel(yearModel); } spinner = addLabeledSpinner(this, labels[1], yearModel); //Make the year be formatted without a thousands separator. spinner.setEditor(new JSpinner.NumberEditor(spinner, "#")); //Add the third label-spinner pair. Date initDate = calendar.getTime(); calendar.add(Calendar.YEAR, -100); Date earliestDate = calendar.getTime(); calendar.add(Calendar.YEAR, 200); Date latestDate = calendar.getTime(); SpinnerDateModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);//ignored for user input dateSpinner = spinner = addLabeledSpinner(this, labels[2], dateModel); spinner.setEditor(new JSpinner.DateEditor(spinner, "MM/yyyy")); //Tweak the spinner's formatted text field. ftf = getTextField(spinner); if (ftf != null) { ftf.setHorizontalAlignment(JTextField.RIGHT); ftf.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 3)); } spinner.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); //XXX: No easy way to get to the buttons and change their border. setSeasonalColor(dateModel.getDate()); //initialize color //Listen for changes on the date spinner. dateSpinner.addChangeListener(this); //Lay out the panel. SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols 10, 10, //initX, initY 6, 10); //xPad, yPad }
From source file:dk.dma.epd.shore.gui.views.SendRouteDialog.java
/** * Configures the given date picker and associated time spinner * /* ww w . j a va 2 s . c o m*/ * @param picker * the date picker * @param spinner * the time spinner */ private void initDatePicker(JXDatePicker picker, JSpinner spinner) { picker.setFormats(new SimpleDateFormat("E dd/MM/yyyy")); picker.addPropertyChangeListener("date", this); DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm"); DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter(); formatter.setAllowsInvalid(false); formatter.setOverwriteMode(true); formatter.setCommitsOnValidEdit(true); spinner.setEditor(editor); spinner.addChangeListener(new SpinnerChangeListener()); }
From source file:es.emergya.ui.gis.popups.ConsultaHistoricos.java
private JSpinner initializeSpinner(final Calendar instance) { JSpinner res = new JSpinner(new SpinnerDateModel()); JSpinner.DateEditor startEditor = new JSpinner.DateEditor(res, "HH:mm:ss"); res.setEditor(startEditor); res.setValue(instance.getTime());/*from w w w. ja va2 s . c o m*/ res.addChangeListener(changeListener); return res; }
From source file:dk.dma.epd.common.prototype.gui.route.RoutePropertiesDialogCommon.java
/** * Configures the given date picker and associated time spinner * @param picker the date picker/* w w w. j a v a 2 s .com*/ * @param spinner the time spinner */ private void initDatePicker(JXDatePicker picker, JSpinner spinner) { picker.setFormats(new SimpleDateFormat("E dd/MM/yyyy")); picker.addPropertyChangeListener("date", this); DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm"); DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter(); formatter.setAllowsInvalid(false); formatter.setOverwriteMode(true); formatter.setCommitsOnValidEdit(true); spinner.setEditor(editor); spinner.addChangeListener(new SpinnerChangeListener()); // Set the enabled state picker.setEnabled(!readOnlyRoute); spinner.setEnabled(!readOnlyRoute); }