United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4689398 Inserting items in a Container with CardLayout does not work since Merlin
JDK-4689398 : Inserting items in a Container with CardLayout does not work since Merlin

Details
Type:
Bug
Submit Date:
2002-05-22
Status:
Closed
Updated Date:
2003-08-15
Project Name:
JDK
Resolved Date:
2002-09-20
Component:
client-libs
OS:
linux_redhat_7.2
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
1.4.1_05 (05)

Related Reports
Backport:
Relates:

Sub Tasks

Description
The CardLayout class in Merlin has been rewritten and is now incompatiable with all previous versions of CardLayout. Instead of using a Hashtable to map the names of the components a Vector of private class Card is used. The CardLayout assumes that the Cards in this Vector are added in the same order as the components in the Container being layed out. This is an incorrect assumption because components can be inserted into a Container and do not always have to be added at the end of the list of components. The following example demonstrates this by inserting components into a Frame with CardLayout. The Components are added in reverse order. When you click on the card it will advance to the next card. On all previous versions of Java next advanced to the next card in the Frame's child list. In Merlin it now advvances to the next Card based on the order they were added. To reproduce, run this program under versions before Merlin and notice the ordering when you click on the Frame and then do the same under Merlin:

 import java.awt.*;
import java.awt.event.*;

public class CardLayoutOrdering
{
	public static void main (String args[])
	{
		Frame f = new Frame();
		f.setLayout(new CardLayout());

		for (int i = 1; i <= 10; i++)
		{
			f.add(new Card(i), String.valueOf(i), 0);
		}
		
		f.setSize(500,500);
		f.setVisible(true);
	}
}

class Card extends Component
{
	public Card (int n)
	{
		index = n;

		addMouseListener(new MouseAdapter()
		{
			public void mousePressed(MouseEvent e)
			{
				CardLayout l = (CardLayout)getParent().getLayout();
				l.next(getParent());
			}
		});

	}
	
	public void paint(Graphics g)
	{
		g.drawString(String.valueOf(index), 100, 100);
	}

	private int index;
}

                                    

Comments
EVALUATION

We should investigate this issue for Mantis. 
###@###.### 2002-05-28


Name: osR10079			Date: 09/04/2002


This is regression from fix for 4362381 (Once the remove button had press, next 
item from the list should show.)  In this fix i've tried to accumulate in 
CardLayout all information for its functionality including order of cards.  
Unfortunately, our usage of CardLayout doesn't provide this information when 
user adds card by Container.add(Component, Object, int).  Thus to fix this 
problem we have to refix original bug (4362381).

###@###.### 2002-09-04

======================================================================
                                     
2002-09-04
SUGGESTED FIX



Name: osR10079			Date: 09/24/2002


See 4546123.

======================================================================
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.1_05
mantis

FIXED IN:
1.4.1_05
mantis

INTEGRATED IN:
1.4.1_05
mantis

VERIFIED IN:
1.4.1_05


                                     
2004-08-24



Hardware and Software, Engineered to Work Together