-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
generic
-
generic
Name: yyT116575 Date: 10/26/2000
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
I opened a panel in each JInternalFrame which is contained in a JDesktopPane. I
then added a mouse listener to each JInternalFrame. The JInternalFrame that is
selected works as expected, but if the mouse moves across any of the other
JInternalFrame, two mouse entered events occur. The mouse exit event works as
expected for all JInternalFrame. This occur with 1.2.2 also.
Source Code:
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Test extends JFrame implements ActionListener
{
public JDesktopPane desktopPane;
private int index = 0;
private int offset = 0;
public Test()
{
desktopPane = new JDesktopPane();
JButton addButton = new JButton("Add Frame");
addButton.addActionListener(this);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(desktopPane, BorderLayout.CENTER);
getContentPane().add("South", addButton);
addWindowListener(new DWAdapter(this));
setSize(300, 300);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
JInternalFrame inFrame1 = new JInternalFrame(Integer.toString(index), true, true, true, true);
inFrame1.getContentPane().setLayout(new BorderLayout());
TestPanel tp1 = new TestPanel(index);
inFrame1.getContentPane().add(tp1, BorderLayout.CENTER);
index++;
desktopPane.add(inFrame1, JLayeredPane.DEFAULT_LAYER);
DesktopManager manager = desktopPane.getDesktopManager();
inFrame1.setBounds(offset,offset, 150, 150);
offset +=30;
inFrame1.setVisible(true);
try {
inFrame1.setSelected(true);
desktopPane.moveToFront(inFrame1);
} catch (java.beans.PropertyVetoException pve) {
System.out.println("Test add frame "+pve.toString());
}
}
/**
* Event handling for the dialog's window mngr.
*/
public class DWAdapter extends WindowAdapter{
Test thisDialog;
public DWAdapter(Test aDialog){
thisDialog=aDialog;
}//end ctor
public void windowClosing(WindowEvent event){
System.exit(0);
}//end windowClosing
}//end WindowAdapter
public class TestPanel extends JPanel implements MouseListener, ActionListener
{
public int id = 0;
public JButton testButton;
public TestPanel(int id)
{
super();
this.id = id;
setBackground(Color.white);
setLayout(new FlowLayout());
addMouseListener(this);
testButton = new JButton(Integer.toString(id));
testButton.addActionListener(this);
add(testButton);
}
public void actionPerformed(ActionEvent ae)
{
System.out.println("Test: actionPerformed ");
}
public void mousePressed (MouseEvent e)
{
System.out.println("TestPanel: mousePressed id="+id);
}
public void mouseClicked (MouseEvent e)
{
System.out.println("TestPanel: mouseClicked id="+id);
}
public void mouseReleased (MouseEvent e)
{
System.out.println("TestPanel: mouseReleased id="+id);
}
public void mouseEntered (MouseEvent e)
{
System.out.println("TestPanel: mouseEntered id="+id);
}
public void mouseExited (MouseEvent e)
{
System.out.println("TestPanel: mouseExited id="+id);
}
}
public static void main(String [] args)
{
(new Test()).setVisible(true);
}
}
1. Run the program
2. Press "Add Frame" button more than once.
3. Enter the cursor into the selected internal frame. Notice only one
MOUSE_ENTERED event.
4. Enter the cursor into an unselected internal frame. Notice two MOUSE_ENTERED
events. -ERROR
5. There is only one MOUSE_EXITED events for all frames.
You may want to check javax.swing.plaf.basic.BasicInternalFrameUI.java
I ran this with VisualCafe's debugger and noticed the mouse entered event was
generated twice here in method forwardMouseEvent. Both setMouseTarget, and
retargetMouseEvent were called in forwardMouseEvent which caused two mouse
entered events.
I hope this is enough.
FYI VisualCafe does not allow me to copy the stack trace to paste here.
Thanks,
Bob
858-592-5274
(Review ID: 110725)
======================================================================