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

Win32: Choice with too many objects to display, should have vertical scrollbar

XMLWordPrintable

    • 1.1
    • x86
    • windows_nt
    • Not verified

      Win32: A Choice control with more items than can be displayed in its list should
      have a vertical scrollbar in the list.

      Steps to reproduce:
      Compile and run the attached code
      <Click> on the Choice open list button
      // Note: there are 21 items in the list, there should be a scrollbar if all 21 are not
          visible.

      import java.awt.*;
      import java.applet.Applet;

      public class ChoiceTest extends Applet
      {
         private Choice choice;
         private int counter = 0;
         public ChoiceTest()
         {
            setLayout( new BorderLayout() );
            add("North", new ChoiceTestCP(this) );
            add("Center", choice = new Choice() );
            choice.addItem("[none]");
            // fill choice list
            for(int i = 0; i < 20; ++i)
               addItem();
         }

         public void init()
         {
            resize(400, 200);
         }

         public void addItem()
         {
            choice.addItem( Integer.toString( ++counter ) );
         }

         public static void main(String argv[])
         {
            AppletFrame.startApplet("ChoiceTest", "Choice Test", argv);
         }
      }


      class ChoiceTestCP extends Panel
      {
         private ChoiceTest applet;
         private final String ADD_ITEM = "Add Item";
         private final String ADD_ITEMS = "Add Items";
         private int counter;
         private TextField field;

         public ChoiceTestCP(ChoiceTest ct)
         {
            applet = ct;
            add( new Label("Count") );
            add( field = new TextField( "1", 10 ) );
            add( new Button(ADD_ITEMS) );
         }

         public boolean action(Event evt, Object obj)
         {

            if( evt.target instanceof Button )
            {
               String label = obj.toString();
               if( label.equals(ADD_ITEM) )
               {
                  applet.addItem();
               }
               else if( label.equals(ADD_ITEMS) )
               {
                  int limit = Integer.parseInt( field.getText().trim() );
                  for( int i = 0; i < limit; ++i )
                     applet.addItem();
               }
               else
                  return false;

               return true;
               

            }
            else
               return super.action(evt, obj);
         }

      }


      /* Generic Applet to Application Frame
       * @(#)AppletFrame.java 1.4 02 Dec 1995 15:28:07
       * @author Kevin A. Smith
       *
       */

      import java.awt.Frame;
      import java.awt.Event;
      import java.awt.Dimension;
      import java.applet.Applet;

      // Applet to Application Frame window
      class AppletFrame extends Frame
      {

          public static void startApplet(String className,
                                         String title,
                                         String args[])
          {
             // local variables
             Applet a;
             Dimension appletSize;

             try
             {
                // create an instance of your applet class
                a = (Applet) Class.forName(className).newInstance();
             }
             catch (ClassNotFoundException e) { return; }
             catch (InstantiationException e) { return; }
             catch (IllegalAccessException e) { return; }

             // initialize the applet
             a.init();
             a.start();
        
             // create new application frame window
             AppletFrame f = new AppletFrame(title);
        
             // add applet to frame window
             f.add("Center", a);
        
             // resize frame window to fit applet
             // assumes that the applet sets its own size
             // otherwise, you should set a specific size here.
             appletSize = a.size();
             f.pack();
             f.resize(appletSize);

             // show the window
             f.show();
        
          } // end startApplet()
        
        
          // constructor needed to pass window title to class Frame
          public AppletFrame(String name)
          {
             // call java.awt.Frame(String) constructor
             super(name);
          }

          // needed to allow window close
          public boolean handleEvent(Event e)
          {
             // Window Destroy event
             if (e.id == Event.WINDOW_DESTROY)
             {
                // exit the program
                System.exit(0);
                return true;
             }
             
             // it's good form to let the super class look at any
             // unhandled events
             return super.handleEvent(e);

          } // end handleEvent()

      } // end class AppletFrame






       

            tballsunw Tom Ball (Inactive)
            kasmithsunw Kevin Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: