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:SpinnerDateEditorSample1.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model = new SpinnerDateModel(); JSpinner spinner = new JSpinner(model); JComponent editor = new JSpinner.DateEditor(spinner); spinner.setEditor(editor); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90);/*from www.ja v a 2 s. c o m*/ frame.setVisible(true); }
From source file:SpinnerNumberEditorSample1.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25); JSpinner spinner = new JSpinner(model); JComponent editor = new JSpinner.NumberEditor(spinner); spinner.setEditor(editor); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90);/*from ww w .j a v a2 s . co m*/ frame.setVisible(true); }
From source file:SpinnerDateEditorSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model = new SpinnerDateModel(); JSpinner spinner = new JSpinner(model); JComponent editor = new JSpinner.DateEditor(spinner, "MMMM yyyy"); spinner.setEditor(editor); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90);//from w w w.j a va2 s .c om frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { SpinnerNumberModel model = new SpinnerNumberModel(0.0, -1000.0, 1000.0, 0.1); JSpinner s = new JSpinner(model); JSpinner.NumberEditor editor = new JSpinner.NumberEditor(s); s.setEditor(editor); JTextField stepText = new JTextField(10); JButton bStepSet = new JButton("Set Step"); bStepSet.addActionListener(e -> { Double val = Double.parseDouble(stepText.getText().trim()); model.setStepSize(val); });//from w w w .ja v a 2s. c om JFrame f = new JFrame(); Container c = f.getContentPane(); c.add(s); JPanel southPanel = new JPanel(); southPanel.add(stepText); southPanel.add(bStepSet); c.add(southPanel, BorderLayout.SOUTH); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:SpinnerNumberEditorSample2.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25); JSpinner spinner = new JSpinner(model); JComponent editor = new JSpinner.NumberEditor(spinner, "#,##0.###"); spinner.setEditor(editor); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90);/*from w w w.j a v a 2 s . c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25); JSpinner spinner = new JSpinner(model); JComponent editor = new JSpinner.NumberEditor(spinner, "#,##0.###"); spinner.setEditor(editor); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90);// w ww .j a v a 2 s . co m frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Spinning"); Container contentPane = frame.getContentPane(); String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; SpinnerModel model = new SpinnerListModel(months); JSpinner spinner = new JSpinner(model); contentPane.add(spinner, BorderLayout.NORTH); SpinnerDateModel model2 = new SpinnerDateModel(); model2.setCalendarField(Calendar.WEEK_OF_MONTH); JSpinner spinner2 = new JSpinner(model2); JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy"); spinner2.setEditor(editor2); frame.getContentPane().add(spinner2, BorderLayout.CENTER); SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5); JSpinner spinner3 = new JSpinner(model3); frame.getContentPane().add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 100);//from w ww . j a v a2s . c om frame.setVisible(true); }
From source file:SpinnerTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Spinning"); Container contentPane = frame.getContentPane(); String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; SpinnerModel model = new SpinnerListModel(months); JSpinner spinner = new JSpinner(model); contentPane.add(spinner, BorderLayout.NORTH); SpinnerDateModel model2 = new SpinnerDateModel(); model2.setCalendarField(Calendar.WEEK_OF_MONTH); JSpinner spinner2 = new JSpinner(model2); JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy"); spinner2.setEditor(editor2); frame.getContentPane().add(spinner2, BorderLayout.CENTER); SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5); JSpinner spinner3 = new JSpinner(model3); frame.getContentPane().add(spinner3, BorderLayout.SOUTH); frame.setSize(200, 100);/*from w w w .j av a 2s . co m*/ frame.show(); }
From source file:net.sf.housekeeper.swing.util.BoundComponentFactory.java
/** * Creates a JSpinner whose value is bound to the given ValueModel. This * means, that the value of the spinner and the value of the ValueModel are * synchronized bidirectionally. Additionally, the spinner uses * the current locale's short format for displaying a date. * //from w ww .j a va2s. co m * @param valueModel the model that provides the value. Must not be null and * must provide {@link Date}objects. * @return A spinner whose value is bound to <code>valueModel</code>. */ public static JSpinner createDateSpinner(final ValueModel valueModel) { assert valueModel != null : "Parameter valueModel must not be null"; assert valueModel.getValue().getClass() .equals(Date.class) : "valueModel must provide Date objects as values"; final SpinnerDateModel model = new SpinnerDateModelAdapter(valueModel); //Need to truncate the current date for correct spinner operation model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); model.setCalendarField(Calendar.DAY_OF_MONTH); final JSpinner spinner = new JSpinner(model); //Set the spinner's editor to use the current locale's short date // format final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT); final String formatPattern = dateFormat.toPattern(); spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern)); return spinner; }
From source file:Main.java
/** * Adds to the given <code>JComponent</code> two date spinners * labeled "To" and "From". Used to specify a specific date range. The * default range is -10 years from today's date through today's date. * @param c - <code>JComponent</code> to add the date spinners to *//* w w w . j a v a2s . com*/ public static void addDateRangePanel(JComponent c) { Calendar calendar = Calendar.getInstance(); JSpinner dateSpinner; //Set up dates Date initDate = calendar.getTime(); Date latestDate = calendar.getTime(); calendar.add(Calendar.YEAR, -10); Date earliestDate = calendar.getTime(); //Date Spinners SpinnerModel fromModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.DAY_OF_MONTH); dateSpinner = addLabeledSpinner(c, "From: ", fromModel, false); dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MM/dd/yyyy")); SpinnerModel toModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.DAY_OF_MONTH); dateSpinner = addLabeledSpinner(c, "To: ", toModel, true); dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MM/dd/yyyy")); }