JPopup / JSpinner not editable

From: Lou Lipnickey (lou.lipnickey_at_pobox.com)
Date: 10/27/04


Date: Wed, 27 Oct 2004 02:04:09 GMT

A JPopup instantiates a JPanel class which contains a bunch of
JSpinners. In the popup, the spinners can be manipulated with the
handles but the text cannot be edited. However, if I put the same JPanel
up, the text is editable, anyone know how to make the spinner text
editable in the popup? Thanks - Lou
Code follows:

import java.awt.*;
import javax.swing.*;
import java.lang.reflect.*;
import java.awt.event.*;

public class Test_Menu1 extends JPanel
{

        public Test_Menu1 ()
        {
                final JPopupMenu popup = new JPopupMenu("hi");
                Dimension screenSize = Toolkit.getDefaultToolkit ( ).getScreenSize ( );
                popup.setLocation ( ( screenSize.width ) / 3, ( screenSize.height ) /
3 );
         popup.add(new ClubAndDistancePanel() );
                JButton button = new JButton ("Club and Distance Popup");
                button.addActionListener(new ActionListener()
                {
             public void actionPerformed(ActionEvent e)
             {
                                popup.setVisible(true);
                 }
         });
                add(button);
                add (new ClubAndDistancePanel() );
        
        }
public Insets getInsets()
        {
                return new Insets(50,50,50,50);
        }

        public static void main(String[] args)
        {
                String name;
                
                try
                {
                        Dimension screenSize = Toolkit.getDefaultToolkit ( ).getScreenSize ( );
                        JPanel panel = new Test_Menu1();
                        JFrame frame = new JFrame("Test");
                        frame.setLocation ( ( screenSize.width ) / 3, ( screenSize.height )
/ 3 );
                        
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        frame.getContentPane().add(panel);
                        frame.pack();
                        frame.setVisible(true);
                }
                catch (Exception e) {e.printStackTrace(); System.exit(0);}
                
        }
}
class ClubAndDistancePanel extends JPanel
{
public ClubAndDistancePanel()
        {
        SpinnerModel clubModel;
        //JSpinner spinner;
          String [] clubs =
        { "Driver","3 wood","4 wood","3 iron","4 iron","5 iron","6 iron","7
iron","8 iron","9 iron","PW ","SW ","LW ","Putter"};
          int [] clubDistances =
        { 240,220,210,190,180,170,160,150,140,130,110,90,80,-1 };
                setLayout(new GridLayout(16,2));

                for (int i=0; i<clubs.length; i++)
                {
                        if ( clubDistances[i]>0 )
                        {
                                clubModel = new SpinnerNumberModel(clubDistances[i],
(clubDistances[i]-clubDistances[i]*.75),
(clubDistances[i]+clubDistances[i]*.75) ,1);
                        }
                        else
                                clubModel = new SpinnerNumberModel(0, 0, 0, 1);
                        //miniPanel=new JPanel( new BoxLayout(miniPanel,BoxLayout.Y_AXIS));

                        JSpinner spinner=new JSpinner(clubModel);
                        spinner.setEditor(new JSpinner.NumberEditor(spinner, "###"));
                        add(new JLabel(clubs[i]));
                        add(spinner);
                }
                add(new JLabel(""));add(new JLabel(""));add(new JLabel(""));
                JButton button = new JButton("Done");
                button.addActionListener(new ActionListener()
                {
             public void actionPerformed(ActionEvent e)
             {
                                System.out.println("exiting");
                                System.exit(0);
                 }
         });
                add(button);
        }
        public Insets getInsets()
        {
                return new Insets(10,10,10,10);
        }
}


Quantcast