Name: gm110360 Date: 03/20/2003
FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows NT version 4.0 SP6
ADDITIONAL OPERATING SYSTEMS :
RedHat Linux 7.2 (2.4.7 kernel)
A DESCRIPTION OF THE PROBLEM :
The componentShown method of the ComponentListener interface as
implemented by java.awt.Component does not get invoked in an MDI
application if a document is already visible. After the first document
(frame) is created and added to the container (desktop), subsequent
frames do not receive the componentShown callback.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the sample code below
2. Click on the empty desktop (application
frame) once. This will create a new frame and add it to the desktop. The
program will output a message to the console when the componentShown and
componentResized messages are received. Once the frame has been created
and added to the desktop, the program will output "---" to indicate that the
process is complete (easier readability).
3. Click on the desktop
again. This will create another new frame and add it to the desktop. Since
the program creates only one type of internal frame, the console output
should be the same for all.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
The componentShown callback should be received every time a
new internal frame is added to the desktop.
Actual:
After the first
frame is created, subsequent new frames that are added to the desktop do
not receive the componentShown callback.
The display of the custom
panel "MyPanel" (which is listening for the componentShown callback) is
implemented as per the JDK documentation. Namely, the internal frame
that holds a MyPanel (BaseInternalFrame)
calls:
setVisible(false);
setVisible(true);
on MyPanel after
creating it.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class
TestFrame extends JFrame
{
JDesktopPane desktop = null;
public TestFrame()
{
// Setup application as MDI
desktop = new JDesktopPane();
setContentPane(desktop);
// Make dragging faster:
desktop.setDoubleBuffered(true);
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); //1.3+ code
// Use mouse "click" to spawn a new internal frame
desktop.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
createFrame();
System.out.println("---");
}
} );
}
protected void createFrame()
{
BaseInternalFrame frame = null;
frame = new BaseInternalFrame();
frame.setVisible(false);
frame.setVisible(true); //necessary as of kestrel
frame.setSize(200,200);
desktop.add(frame);
try
{
frame.setSelected(true);
}
catch (java.beans.PropertyVetoException e) { ; }
}
public static void main(String[] args)
{
JFrame f = new TestFrame();
f.setBounds(100, 100, 300, 300);
f.setVisible(true);
}
}
class BaseInternalFrame extends JInternalFrame
{
public static int InternalFrameCount = 0;
public BaseInternalFrame()
{
super("Sample Internal Frame",
true, //resizable
true, //closable
true, //maximizable
true); //iconifiable
CreateGUI(); //Create the GUI and put it in the window...
pack(); // Then set the window size or call pack...
setLocation(20 * InternalFrameCount, 20 * InternalFrameCount);
setDoubleBuffered(true);
InternalFrameCount++;
}
protected void CreateGUI()
{
JComponent c = (JComponent)getContentPane();
c.setLayout(new BorderLayout() );
JPanel p = new MyPanel();
c.add(p,BorderLayout.CENTER);
p.setVisible(false);
p.setVisible(true);
}
}
class MyPanel extends JPanel
{
public MyPanel()
{
setLayout(new BorderLayout());
JLabel l = new JLabel("A label.");
add(l,BorderLayout.CENTER);
addComponentListener(new ComponentAdapter()
{
public void componentResized(ComponentEvent e)
{
System.out.println("[ MyPanel ] resized");
}
public void componentShown(ComponentEvent e)
{
System.out.println("[ MyPanel ] shown");
}
} );
}
}
---------- END SOURCE ----------
(Review ID: 146053)
======================================================================