List of usage examples for javax.swing JSpinner JSpinner
public JSpinner(SpinnerModel model)
From source file:Main.java
public Main() { Calendar cal = Calendar.getInstance(); Date date = cal.getTime();/* ww w . ja v a 2s . com*/ model.setValue(date); spinner = new JSpinner(model); spinner.addChangeListener(e -> { Date d = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(d)); } }); format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); format.applyPattern("HH:mm:ss"); panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i] = new SimpleDateFormat("HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); labels[i].setHorizontalAlignment(JLabel.RIGHT); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout(10, 10)); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:MonthSpinner.java
public MonthSpinner() { super("Month Spinner"); setSize(200, 100);/*from ww w . j a va 2 s.co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4)); c.add(new JLabel("Expiration Date:")); Date today = new Date(); // Start the spinner today, but don't set a min or max date // The increment should be a month JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH)); JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy"); s.setEditor(de); c.add(s); setVisible(true); }
From source file:Main.java
public Main() { super("JSpinner Icon Test"); setSize(300, 80);/*from ww w .java2s .c o m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new GridLayout(0, 2)); Icon nums[] = new Icon[] { new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif"), new ImageIcon("4.gif"), new ImageIcon("5.gif"), new ImageIcon("6.gif") }; JSpinner s1 = new JSpinner(new SpinnerListModel(nums)); s1.setEditor(new IconEditor(s1)); c.add(new JLabel(" Icon Spinner")); c.add(s1); setVisible(true); }
From source file:IconSpinner.java
public IconSpinner() { super("JSpinner Icon Test"); setSize(300, 80);/*www . jav a2 s . co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new GridLayout(0, 2)); Icon nums[] = new Icon[] { new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif"), new ImageIcon("4.gif"), new ImageIcon("5.gif"), new ImageIcon("6.gif") }; JSpinner s1 = new JSpinner(new SpinnerListModel(nums)); s1.setEditor(new IconEditor(s1)); c.add(new JLabel(" Icon Spinner")); c.add(s1); setVisible(true); }
From source file:Main.java
/** * Creates a <code>JSpinner</code> with the specified label text from the given * <code>SpinnerModel</code> and adds the <code>JSpinner</code> to the given * <code>Container</code>./*from w w w . j a v a 2s . c om*/ * @param c - the container to add the spinner to * @param label - the text which to add to the spinner * @param model - the <code>SpinnerModel</code> to make the spinner from * @return a JSpinner created from the <code>SpinnerModel</code> with the * specified label text */ public static JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model) { JLabel l = new JLabel(label); c.add(l); JSpinner spinner = new JSpinner(model); l.setLabelFor(spinner); c.add(spinner); return spinner; }
From source file:Main.java
public void makeUI() { String[] zones = { "Asia/Tokyo", "Asia/Hong_Kong", "Asia/Calcutta", "Europe/Paris", "Europe/London", "America/New_York", "America/Los_Angeles" }; JLabel[] labels = new JLabel[zones.length]; SimpleDateFormat[] formats = new SimpleDateFormat[zones.length]; JFrame frame = new JFrame(); Calendar cal = Calendar.getInstance(); Date date = cal.getTime();/*ww w.j a v a 2s . c o m*/ SpinnerDateModel model = new SpinnerDateModel(); model.setValue(date); JSpinner spinner = new JSpinner(model); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Date date = (Date) ((JSpinner) e.getSource()).getValue(); for (int i = 0; i < labels.length; i++) { labels[i].setText(formats[i].format(date)); } } }); SimpleDateFormat format = ((JSpinner.DateEditor) spinner.getEditor()).getFormat(); format.setTimeZone(TimeZone.getTimeZone(zones[0])); format.applyPattern("yyyy-MM-dd HH:mm:ss"); JPanel panel = new JPanel(new GridLayout(zones.length, 2, 10, 10)); for (int i = 0; i < zones.length; i++) { formats[i] = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); formats[i].setTimeZone(TimeZone.getTimeZone(zones[i])); JLabel label = new JLabel(zones[i]); labels[i] = new JLabel(formats[i].format(date)); panel.add(label); panel.add(labels[i]); } frame.setLayout(new BorderLayout()); frame.add(spinner, BorderLayout.NORTH); frame.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
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 www .j a v a 2 s . c o 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:ch.zhaw.ias.dito.ui.util.SingleHistogramPanel.java
public SingleHistogramPanel(Matrix m) { super(new BorderLayout()); this.m = m;/*from ww w. ja v a2s . co m*/ this.chart = createChart(); this.chartPanel = new ChartPanel(this.chart); Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder()); this.chartPanel.setBorder(border); add(this.chartPanel, BorderLayout.CENTER); JPanel dashboard = new JPanel(new BorderLayout()); dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4)); this.spinner = new JSpinner(new SpinnerNumberModel(0, 0, m.getColCount() - 1, 1)); spinner.addChangeListener(this); this.slider = new JSlider(0, m.getColCount() - 1, 0); slider.setPaintLabels(true); slider.setMajorTickSpacing(Math.max(50, 10 * Math.round(m.getColCount() / 100))); slider.setPaintTicks(true); this.slider.addChangeListener(this); FormLayout layout = new FormLayout("fill:0:g, max(20dlu; pref)", "top:pref"); CellConstraints cc = new CellConstraints(); DefaultFormBuilder fb = new DefaultFormBuilder(layout, Translation.INSTANCE.getBundle()); fb.add(slider, cc.xy(1, 1)); fb.add(spinner, cc.xy(2, 1)); dashboard.add(fb.getPanel(), BorderLayout.CENTER); add(dashboard, BorderLayout.SOUTH); switchColumn(0); }
From source file:QandE.Beeper2.java
public Beeper2() { super(new BorderLayout()); //Create and set up the spinner. String numBeepsString = "Number of Beeps: "; beepsModel = new SpinnerNumberModel(1, 1, 10, 1); JLabel numBeepsLabel = new JLabel(numBeepsString); add(numBeepsLabel, BorderLayout.PAGE_START); JSpinner spinner = new JSpinner(beepsModel); numBeepsLabel.setLabelFor(spinner);//ww w . j ava 2 s .c om add(spinner, BorderLayout.CENTER); button = new JButton("Click Me"); button.setPreferredSize(new Dimension(200, 80)); add(button, BorderLayout.PAGE_END); button.setActionCommand(BUTTON_CMD); button.addActionListener(this); }
From source file:Main.java
/** * Creates a <code>JSpinner</code> with the specified label text from the given * <code>SpinnerModel</code> and adds the <code>JSpinner</code> to the given * <code>Container</code>. If the wrap parameter is set to true, MigLayout's * "wrap" attribute will be applied to the <code>JTextField</code>, meaning * the next component added will appear on the next line. * (Exception: Will not work if MigLayout's flowy layout constraint is applied, * but it is rarely used MigLayout feature and thus not a common concern; however * if you have set this layout constraint on your <code>JComponent</code> do not * attempt to use the wrap option of this method.) * @param c - the container to add the spinner to * @param label - the text which to add to the spinner * @param model - the <code>SpinnerModel</code> to make the spinner from * @param wrap - indicates whether the MigLayout "wrap" attribute should be * present when this <code>JSpinner</code> is added to the container; if * component does not have the MigLayout as it's layout manager then this * property has no effect/*from w ww .ja v a2 s. com*/ * @return a JSpinner created from the <code>SpinnerModel</code> with the * specified label text */ public static JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model, boolean wrap) { JLabel l = new JLabel(label); c.add(l, "align left"); JSpinner spinner = new JSpinner(model); l.setLabelFor(spinner); if (wrap) { c.add(spinner, "align left, wrap"); } else { c.add(spinner, "align left, split"); } return spinner; }