Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4110505

JPopup is not serializable

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      swing1.0fcs
    • CPU:
      sparc
    • OS:
      solaris_2.5, solaris_2.5.1, solaris_2.6

      Description



      Name: eiC57698 Date: 02/09/98



        JPopup menu throws java.io.NotSerializableException on
       com.sun.java.swing.JPopupMenu$MouseGrabber

        Here is test case. Execute it, press down arrow on top combo box to
       activate popup, hide popup, press "Serialize" button.
      ----------------------------------------------------------------------
      /*
       * Experiments with comboBox
       */

      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;
      import com.sun.java.swing.*;
      import com.sun.java.swing.organic.*;

      public class ComboBoxTest extends JFrame implements
      ItemListener, ActionListener {
        // The initial width and height of the frame
        public static int WIDTH = 300;
        public static int HEIGHT = 300;
        
        Button serializeButton=null;
        JComboBox days;

        public ComboBoxTest(String lab) {
          super(lab);
          
          // create each button
          days = new JComboBox( );
          days.addItem( "Sunday" );
          days.addItem( "Monday" );
          days.addItem( "Tuesday");
          days.addItem( "Wednesday");
          days.addItem( "Thursday");
          days.addItem( "Friday");
          days.addItem( "Saturday" );
          days.addItemListener( this );
          days.addActionListener( this );

          JComboBox months = new JComboBox();
          months.addItem( "Jan" );
          months.addItem( "Feb" );
          months.addItem( "Mar" );
          months.addItem( "Apr" );
          months.addItem( "May" );
          months.addItem( "Jun" );
          months.addItem( "Jul" );
          months.addItem( "Aug" );
          months.addItem( "Sep" );
          months.addItem( "Oct" );
          months.addItem( "Nov" );
          months.addItem( "Dec" );

          // Add to buttons for serialization/deserialization
          serializeButton = new Button( "Serialize" );
          serializeButton.addActionListener( this );
          
          // Get contents area
          Container content = getContentPane();
          // Set layout to GridLayout - 2 rows x 1 column
          content.setLayout( new GridLayout( 4, 1 ));
          // add to screen
          content.add( days );
          content.add( serializeButton );
          content.add( months );
        }

        public static void main (String args[]) {
          ComboBoxTest frame = new ComboBoxTest("First Swing Stuff");

          frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
            public void mouseExited( WindowEvent e ) { System.out.println( "Mouse ex" );}
          });

          frame.setSize(WIDTH, HEIGHT);
          frame.setVisible(true);
        }

        public void actionPerformed( ActionEvent e ) {
          System.out.println( "actionPerformed " + e.getActionCommand());
          Object obj=e.getSource();
          if ( obj instanceof Button ) {
            String lab=e.getActionCommand();
            if ( lab.equals( "Serialize") ) {
      System.out.println( "Serialization of ComboBoxes" );
      try {
      FileOutputStream f =
      new FileOutputStream( "ComboBoxTestComboBoxes.ser" );
      ObjectOutput s = new ObjectOutputStream( f );
      s.writeObject( "Days combobox" );
      s.writeObject( days );
      s.flush();
      } catch ( Exception exc ) {
      System.err.println( "An exception occured while serialize days" +
      exc.getMessage());
      exc.printStackTrace();
      }
            }
          }
        }

        public void itemStateChanged( ItemEvent e ) {
          System.out.println( "itemState " + e.getItem() );
        }
      }
      -------------------------------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            tballsunw Tom Ball (Inactive)
            Reporter:
            eilyin Evgeni Ilyin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: