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

JComboBox popup has painting problems.

XMLWordPrintable



      Name: eiC57698 Date: 02/09/98



       JComboBox popup has painting problems when used with standard AWT
       components.

        Here is test case. Execute it, press down arrow on top combo box to
       activate popup. Popup will be partially hidden by "Serialize" button,
       visible part of popup will appear in the bottom combo box.

      ----------------------------------------------------------------------
      /*
       * 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() );
        }
      }
      -------------------------------------------------------------------------------

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

            tsantossunw Tom Santos (Inactive)
            eilyin Evgeni Ilyin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: