bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/26951] New: Problems with DefaultComboBoxModel


From: subanark at gmail dot com
Subject: [Bug classpath/26951] New: Problems with DefaultComboBoxModel
Date: 30 Mar 2006 19:40:29 -0000

The DefaultComboBoxModel class has a couple of incompadibilities with Sun's
implementation.

1. If you set a selected item when the model is empty, and then add an element,
the new added element is selected (as opposed to sun's version where it is only
selected if the currently selected element is null)

2. Classpath access the underlining vector in too many methods. Sun's
implementation only accesses it in the direct access methods, and calls the
access methods in other methods.

The following code demonstrates such incompadibility

import javax.swing.DefaultComboBoxModel;
import java.util.Vector;
public class EmptyComboBoxModel extends DefaultComboBoxModel
{
   public EmptyComboBoxModel()
   {
      super((Vector<?>)null);
   }

   public int getSize()
   {
      return 0;
   }

   public Object getElementAt(int index)
   {
      return null;
   }

   public int getIndexOf(Object anObject)
   {
      return -1;
   }

   public static void main(String[] args)
   {
      try
      {
         new EmptyComboBoxModel();
         System.out.println("Construction of EmptyComboBoxModel succeeded");
      }
      catch(NullPointerException e)
      {
         System.out.println("Construction of EmptyComboBoxModel failed");
      }
      DefaultComboBoxModel model = new DefaultComboBoxModel(new Vector());
      model.setSelectedItem("Value1");
      model.addElement("Value2");
      System.out.println("Selected Element:"+model.getSelectedItem());
   }
}

Output in Sun's implementation:
Construction of EmptyComboBoxModel succeeded
Selected Element:Value1

Output in classpath's implementation:
Construction of EmptyComboBoxModel failed
Selected Element:Value2

The construction of classpath's version failed since it asked the passed vector
its size, whereas sun's implementation just called getSize()

other very minor issues:
The removeElementAt(int) method alters the Vector first then changes the
selected item, whereas Sun's version changes the selected item and then alters
the vector.

Sun calls vector's functions by the same name as  the model's method's name
(e.g. addElement(Object) calls addElement(Object) in Vector) which is
noticeable if you subclass Vector.


-- 
           Summary: Problems with DefaultComboBoxModel
           Product: classpath
           Version: 0.90
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: subanark at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26951





reply via email to

[Prev in Thread] Current Thread [Next in Thread]