List of usage examples for javax.swing SpinnerListModel SpinnerListModel
public SpinnerListModel(Object[] values)
SpinnerModel
whose sequence of values is defined by the specified array. From source file:Main.java
public Main() { super("JSpinner Icon Test"); setSize(300, 80);//w ww . j a v a 2s. 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)); System.out.println(s1.getEditor()); c.add(new JLabel(" Icon Spinner")); c.add(s1); setVisible(true); }
From source file:MainClass.java
public MainClass() { super("JSpinner Icon Test"); setSize(300, 80);/*from w ww.j a va 2 s . 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:Main.java
public SpinnerEditor(String[] items) { spinner.setModel(new SpinnerListModel(Arrays.asList(items))); }
From source file:Main.java
public Main() { super("JSpinner Icon Test"); setSize(300, 80);/*from ww w . j ava 2 s .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);/* w ww . j a v a 2 s. c om*/ 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:SwingSpinnerTest.java
public SwingSpinnerTest() { super("JSpinner Test"); setSize(300, 180);/*from www.j a va 2 s .co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new GridLayout(0, 2)); c.add(new JLabel(" Basic Spinner")); c.add(new JSpinner()); c.add(new JLabel(" Date Spinner")); c.add(new JSpinner(new SpinnerDateModel())); String weekdays[] = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; c.add(new JLabel(" List Spinner")); c.add(new JSpinner(new SpinnerListModel(weekdays))); c.add(new JLabel(" Number Spinner")); c.add(new JSpinner(new SpinnerNumberModel(0, 0, 100, 5))); c.add(new JLabel(" Rollover List Spinner")); c.add(new JSpinner(new RolloverSpinnerListModel(weekdays))); setVisible(true); }
From source file:Main.java
public Main() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);//from www .j av a2 s.c om add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JSpinner defaultSpinner = new JSpinner(); addRow("Default", defaultSpinner); JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5)); addRow("Bounded", boundedSpinner); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts)); addRow("List", listSpinner); JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) { public Object getNextValue() { return super.getPreviousValue(); } public Object getPreviousValue() { return super.getNextValue(); } }); addRow("Reverse List", reverseListSpinner); JSpinner dateSpinner = new JSpinner(new SpinnerDateModel()); addRow("Date", dateSpinner); JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel()); String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern(); betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern)); addRow("Better Date", betterDateSpinner); JSpinner timeSpinner = new JSpinner(new SpinnerDateModel()); pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern(); timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern)); addRow("Time", timeSpinner); JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat")); addRow("Word permutations", permSpinner); }
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 w w w.j a v a 2s . 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(); 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:SpinnerTest.java
public SpinnerFrame() { setTitle("SpinnerTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);//from w ww .j a v a 2 s. co m add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JSpinner defaultSpinner = new JSpinner(); addRow("Default", defaultSpinner); JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5)); addRow("Bounded", boundedSpinner); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts)); addRow("List", listSpinner); JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) { public Object getNextValue() { return super.getPreviousValue(); } public Object getPreviousValue() { return super.getNextValue(); } }); addRow("Reverse List", reverseListSpinner); JSpinner dateSpinner = new JSpinner(new SpinnerDateModel()); addRow("Date", dateSpinner); JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel()); String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern(); betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern)); addRow("Better Date", betterDateSpinner); JSpinner timeSpinner = new JSpinner(new SpinnerDateModel()); pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern(); timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern)); addRow("Time", timeSpinner); JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat")); addRow("Word permutations", permSpinner); }
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); }// w w w. ja va 2s . com 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 }