Java by API/javax.swing/SpinnerListModel — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:18, 31 мая 2010
extends SpinnerListModel [Circle Spinner Model]
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("JSpinner Dates");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SpinnerModel model3 = new RolloverSpinnerListModel(new String[]{"a","b","c"});
JSpinner spinner3 = new JSpinner(model3);
frame.add(spinner3, BorderLayout.SOUTH);
frame.setSize(200, 90);
frame.setVisible(true);
}
}
class RolloverSpinnerListModel extends SpinnerListModel {
public RolloverSpinnerListModel(List<?> values) {
super(values);
}
public RolloverSpinnerListModel(Object[] values) {
super(values);
}
public Object getNextValue() {
Object returnValue = super.getNextValue();
if (returnValue == null) {
returnValue = getList().get(0);
}
return returnValue;
}
public Object getPreviousValue() {
Object returnValue = super.getPreviousValue();
if (returnValue == null) {
List list = getList();
returnValue = list.get(list.size() - 1);
}
return returnValue;
}
}
new SpinnerListModel()
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("JSpinner Dates");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SpinnerModel model1 = new SpinnerListModel();
JSpinner spinner1 = new JSpinner(model1);
JLabel label1 = new JLabel("None");
JPanel panel1 = new JPanel(new BorderLayout());
panel1.add(label1, BorderLayout.WEST);
panel1.add(spinner1, BorderLayout.CENTER);
frame.add(panel1, BorderLayout.NORTH);
frame.setSize(200, 90);
frame.setVisible(true);
}
}
new SpinnerListModel(Object[] days)
import java.awt.BorderLayout;
import java.text.DateFormatSymbols;
import java.util.Locale;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;
public class MainClass {
public static void main(String args[]) {
JFrame f = new JFrame("JSpinner Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH);
String days[] = symbols.getWeekdays();
SpinnerModel model1 = new SpinnerListModel(days);
SpinnerModel model2 = new SpinnerDateModel();
JSpinner spinner1 = new JSpinner(model1);
JSpinner spinner2 = new JSpinner(model2);
f.add(spinner1, BorderLayout.NORTH);
f.add(spinner2, BorderLayout.SOUTH);
f.setSize(300, 100);
f.setVisible(true);
}
}