The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JSpinner  [8 examples]

e788. Disabling Keyboard Editing in a JSpinner Component

    // Create a nummber spinner
    JSpinner spinner = new JSpinner();
    
    // Disable keyboard edits in the spinner
    JFormattedTextField tf =
        ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField();
    tf.setEditable(false);
    
    // The previous call sets the background to a disabled
    // color (usually gray). To change this disabled color,
    // reset the background color.
    tf.setBackground(Color.white);
    
    // The value of the spinner can still be programmatically changed
    spinner.setValue(new Integer(100));

 Related Examples
e786. Creating a JSpinner Component
e787. Creating an Hour JSpinner Component
e789. Limiting the Values in a Number JSpinner Component
e790. Setting the Margin Space on a JSpinner Component
e791. Customizing the Editor in a JSpinner Component
e792. Creating a SpinnerListModel That Loops Through Its Values
e793. Listening for Changes to the Value in a JSpinner Component

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.