-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.1
-
None
-
x86
-
windows_nt
Name: joT67522 Date: 09/16/97
REPRODUCTION
------------
1) Create a subclass of Component which saves a data pointer to
a PopupMenu, and which adds the PopupMenu to itself using the
void add(PopupMenu) method in Component. Make the Component
subclass implement Serializable.
2) Serialize the Component to a ObjectOutputStream.
3) Read the object back in from a ObjectInputStream.
4) The PopupMenu (which was serialized with the component because
there was a non-transient pointer to it defined as a data
member of the Component subclass) will have "lost" it's
parent Component. Therefore, the menu will throw an exception
when it's void show() method is called.
SAMPLE SOURCE CODE
------------------
// Package and import declarations
import java.util.*;
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
public class TestComponent extends Container implements Serializable
{
/**
* Popup menu of Presentations
*/
PopupMenu testMenu;
/**
* Empty constructor needed for serialization
*/
public TestComponent()
{
// Call component constructor
super();
// Turn on mouse events for popup menus
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
// Add presentation list items to a menu
addMenuItems(menuItemList);
}
private void addMenuItems(Vector mi)
{
// Check if a menu is required
if (mi.size() > 0)
{
MenuItem mi;
if (testMenu == null)
{
testMenu = new PopupMenu();
// Add a menu item for each item on the list
for(int i = 0; i < menuItemList.size(); i++)
{
// Put title of Presentation into menu item.
// Use Presentation index as the value of the menu item.
mi = (MenuItem) menuItemList.elementAt(i);
testMenu.add(mi);
}
// Add the popup to the parent symbol
add(testMenu);
}
}
}
/**
* Processes mouse events and shows the test menu if the mouse
* event is a popup trigger
*/
public void processMouseEvent(MouseEvent evt)
{
if (evt.isPopupTrigger())
{
if (testMenu != null)
{
testMenu.show(this, evt.getX(), evt.getY());
}
}
}
}
company - Software Productivity Solutions , email - ###@###.###
======================================================================
- duplicates
-
JDK-4047020 PopupMenu parents aren't restored when un-serialized
-
- Closed
-