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

Document java.awt.List() constructor's default setting of four (4) visible items

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • docs
    • beta
    • generic
    • generic



      Name: krT82822 Date: 03/05/2000


      orig synopsis: "java.awt.List.getRows() Returns Incorrect Value Always"

      5 Mar 2000, eval1127@eng -- the default value of 4 (items to be shown) must be made explicit in the docs, vs. subliminally (as it has been for a long time,
      via the example noting "new List(4,...)" followed by a picture showing 4 visible items, though the list is much longer).

      (see also 4161364, 4032361)

      In the user's example:

      < final java.awt.List l = new java.awt.List(10); // shows 10 items
      --- (vs.)
      > final java.awt.List l = new java.awt.List(); // will show 4 items (default)

      ----------------

      Welcome to the 20th century (nevermind 21). This is a Mac. There IS no "java -
      version command". Weren't you the ones who touted write once... Nevermind.
      This was tested under MRJ 2.2 (JDK 1.1.8), but the bug seems to be in Sun's code,
      in List.java 1.62 99/01/22. (Sorry for the snide remark, but every visit to this
      web site is filled with frustration of corporate lies like write once run
      anywhere, and NONE of the "Operating System" popup choices contained MacOS.)


      java.awt.List.getRows() always returns the same value, regardless of how many
      items are actually showing in the List. The number returned is the number of
      rows initially visible when the List was first shown.

        From the 1.1.7 javadoc:


        public int getRows()
            Get the number of visible lines in this list.
            Returns:
                   the number of visible lines in this scrolling list.


      Here is a simple test case:

      public class Foo extends java.awt.Frame
      {
        public Foo()
        {
          super("Foo");

          final java.awt.List l = new java.awt.List();
          
          add(l);
          
          l.addItem("1");
          l.addItem("2");
          l.addItem("3");
          l.addItem("4");
          l.addItem("5");
          l.addItem("6");
          l.addItem("7");
          l.addItem("8");
          l.addItem("9");
          l.addItem("10");
          
          l.addComponentListener(new java.awt.event.ComponentAdapter()
          {
            public void componentResized(java.awt.event.ComponentEvent e)
            {
              System.out.println(l.getRows());
            }
          });

          pack();
          setVisible(true);
        }
        
        
        public static void main(String[] args)
        {
          new Foo();
        }
      }

      As you resize the Frame, the value of List.getRows() is printed to System.out.
      You'll notice right away that the same number is always printed out.

      In List.java, the field rows is set during construction and never changed; and
      getRows() simply returns that value. In fact, all the get...Size(int rows)
      methods refer to that field.

      Peace,
      <username>
      (Review ID: 102080)
      ======================================================================



      Had a quick look at the source. Yes, it's pretty clear. If you don't specify a non-zero number of rows, then a default of 4 rows is created. And the doc for the rows variable states that the value "rows" can not be changed. It all seems pretty straightforward, but I added loads of text to make it clear as a bell. Fixed for merlin.
      sharonz@eng 2000-04-05

            sharonz Sharon Zakhour (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: