Java Reference
In-Depth Information
Example 14-8. SpinnerDemo.java
public
public class
class SpinnerDemo
SpinnerDemo {
public
public static
void main ( String [] args ) {
JFrame jf = new
static void
new JFrame ( "It Spins" );
Container cp = jf . getContentPane ();
cp . setLayout ( new
new GridLayout ( 0 , 1 ));
// Create a JSpinner using one of the pre-defined SpinnerModels
JSpinner dates = new
new JSpinner ( new
new SpinnerDateModel ());
cp . add ( dates );
// Create a JSPinner using a SpinnerListModel.
String [] data = { "One" , "Two" , "Three" };
JSpinner js = new
new JSpinner ( new
new SpinnerListModel ( data ));
cp . add ( js );
jf . setSize ( 100 , 80 );
jf . setVisible ( true
true );
}
}
Figure 14-9. SpinnerDemo output
JSpinner 's editors are reasonably clever. For example, if you select the leading zero of a
number (such as the 04 in 2004 ), and try to increment it, the editor updates the entire number
( 04 to 05 ) rather than producing something silly like 15 .
See Also
The earlier Swing classes JList and JComboBox also let you choose among values.
Search WWH ::




Custom Search