List of usage examples for javax.swing SpinnerDateModel SpinnerDateModel
public SpinnerDateModel(Date value, Comparable<Date> start, Comparable<Date> end, int calendarField)
SpinnerDateModel
that represents a sequence of dates between start
and end
. From source file:MainClass.java
public MainClass() { super("Month Spinner"); setSize(200, 100);//from w w w . j a v a2 s . c o 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(); 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("Month Spinner"); setSize(200, 100);//from w w w . j a va2s.c o 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(); 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); try { s.commitEdit(); } catch (ParseException e) { e.printStackTrace(); } }
From source file:Main.java
public Main() { setSize(200, 100);// w w w.j a v a 2s . 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() { JSpinner m_dateSpinner;/*from w w w . j a v a 2s. c o m*/ SpinnerDateModel m_dateSpinnerModel; Calendar rightNow = Calendar.getInstance(); Date current = rightNow.getTime(); rightNow.set(Calendar.HOUR_OF_DAY, -24); Date start = rightNow.getTime(); rightNow.set(Calendar.HOUR_OF_DAY, 48); Date end = rightNow.getTime(); int step = Calendar.HOUR_OF_DAY; m_dateSpinnerModel = new SpinnerDateModel(current, start, end, step); m_dateSpinner = new JSpinner(m_dateSpinnerModel); add(m_dateSpinner); }
From source file:MonthSpinner.java
public MonthSpinner() { super("Month Spinner"); setSize(200, 100);/*from ww w. ja v a 2 s .c o 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 DateSpinner(String format, Date date) { super(new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY)); setFormat(format);/*from www. j a v a 2s. co m*/ customizeSpinner(); }
From source file:components.SpinnerDemo.java
public SpinnerDemo(boolean cycleMonths) { super(new SpringLayout()); String[] labels = { "Month: ", "Year: ", "Another Date: " }; int numPairs = labels.length; Calendar 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 www. j av a 2 s . co 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(); SpinnerModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);//ignored for user input spinner = addLabeledSpinner(this, labels[2], dateModel); spinner.setEditor(new JSpinner.DateEditor(spinner, "MM/yyyy")); //Lay out the panel. SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols 10, 10, //initX, initY 6, 10); //xPad, yPad }
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 a v a2 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:com.anrisoftware.prefdialog.fields.spinner.SpinnerField.java
private SpinnerModel createDateModel() { Object value = getValue();//w w w. j ava 2 s . co m if (!(value instanceof Date)) { return null; } long[] start = annotationAccess.getValue(START_ATTRIBUTE); long[] end = annotationAccess.getValue(END_ATTRIBUTE); int field = annotationAccess.getValue(CALENDAR_FIELD_ATTRIBUTE); Comparable<?> cstart = start.length == 0 ? null : new Date(start[0]); Comparable<?> cend = end.length == 0 ? null : new Date(end[0]); return new SpinnerDateModel((Date) value, cstart, cend, field); }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initToolBar() { toolbar = new JToolBar("ToolBar", JToolBar.HORIZONTAL); // Add Button addButton = new JButton(); addButton.setActionCommand(""); addButton.setToolTipText(""); addButton.setIcon(new ImageIcon(getClass().getResource("edit-add-3.png"))); // Search date range radio buttons ButtonGroup group = new ButtonGroup(); yearToggleButton = new JToggleButton(); yearToggleButton.setToolTipText(""); yearToggleButton.setIcon(new ImageIcon(getClass().getResource("year-s.png"))); group.add(yearToggleButton);//from w w w .j a v a 2 s . c o m monthToggleButton = new JToggleButton(); monthToggleButton.setToolTipText(""); monthToggleButton.setIcon(new ImageIcon(getClass().getResource("month-s.png"))); group.add(monthToggleButton); dayToggleButton = new JToggleButton(); dayToggleButton.setToolTipText(""); dayToggleButton.setIcon(new ImageIcon(getClass().getResource("day-s.png"))); group.add(dayToggleButton); customToggleButton = new JToggleButton(); customToggleButton.setToolTipText(""); customToggleButton.setIcon(new ImageIcon(getClass().getResource("all-s.png"))); group.add(customToggleButton); // ??Checkbox monthToggleButton.setSelected(true); Calendar earliestCalendar = Calendar.getInstance(); earliestCalendar.add(Calendar.YEAR, -100); java.util.Date earliestDate = earliestCalendar.getTime(); Calendar latestCalendar = Calendar.getInstance(); latestCalendar.add(Calendar.YEAR, 100); java.util.Date latestDate = latestCalendar.getTime(); // 3? Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -1); calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date initDate = calendar.getTime(); SpinnerDateModel startDateModel = new SpinnerDateModel(DateUtil.getStartOfWeek(), earliestDate, latestDate, Calendar.MONTH); startDateSpinner = new JSpinner(startDateModel); JSpinner.DateEditor startDateEditor = new JSpinner.DateEditor(startDateSpinner, "yyyy-MM-dd"); startDateSpinner.setEditor(startDateEditor); calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DAY_OF_MONTH, -1); initDate = calendar.getTime(); SpinnerDateModel endDateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.MONTH); endDateSpinner = new JSpinner(endDateModel); JSpinner.DateEditor endDateEditor = new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd"); endDateSpinner.setEditor(endDateEditor); // Keyword text field keywordTextField = new JTextField(); keywordTextField.setPreferredSize(new Dimension(250, 20)); keywordTextField.setMaximumSize(keywordTextField.getPreferredSize()); // Search Button searchButton = new JButton(); searchButton.setActionCommand("?"); searchButton.setToolTipText("?"); searchButton.setIcon(new ImageIcon(getClass().getResource("edit-find-5.png"))); // Layout cards = new JPanel(); cards.setLayout(new CardLayout()); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); startDateSpinner.setPreferredSize(new Dimension(90, 20)); startDateSpinner.setMaximumSize(startDateSpinner.getPreferredSize()); box.add(startDateSpinner); box.add(Box.createHorizontalStrut(6)); endDateSpinner.setPreferredSize(new Dimension(90, 20)); endDateSpinner.setMaximumSize(endDateSpinner.getPreferredSize()); box.add(endDateSpinner); cards.add(new JPanel(), HIDE_DATE_CHOOSER); cards.add(box, SHOW_DATE_CHOOSER); Box dateRangeBox = Box.createHorizontalBox(); dateRangeBox.add(Box.createHorizontalGlue()); dateRangeBox.add(cards); toolbar.add(addButton); toolbar.add(dateRangeBox); toolbar.add(customToggleButton); toolbar.add(yearToggleButton); toolbar.add(monthToggleButton); toolbar.add(dayToggleButton); toolbar.add(keywordTextField); toolbar.add(searchButton); add(toolbar, BorderLayout.NORTH); // Event listener addButton.addActionListener(e -> showAddRecordDialog()); ActionListener listener = e -> searchRecords(); yearToggleButton.addActionListener(listener); monthToggleButton.addActionListener(listener); dayToggleButton.addActionListener(listener); customToggleButton.addActionListener(listener); keywordTextField.addActionListener(listener); searchButton.addActionListener(listener); customToggleButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { chooseDateRange(); } } }); }