JDK-4516021 : Clicking on close box of JInternalFrame doesn't consume the event
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-10-17
  • Updated: 2001-11-16
  • Resolved: 2001-11-16
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 10/17/2001


java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)

This bug is only present in 1.4.0-beta2, not in 1.3

1. Compile and run the code below
2. If there is no active caret, place it at the start of the text field
3. Click "Show Palette"
4. Close the frame by clicking on its close box.
5. Observe the caret move to the location of the mouse click

In my application, I use JInternalFrame as a floating palette that shows
properties of the underlying selected text.  Because of this problem, when the
user closes the palette, the current selection disappears.

---------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test1 extends JPanel
{
   JEditorPane pane = new JEditorPane();
   JInternalFrame iFrame = new JInternalFrame("iTest");
   
   public static void main( String[] args )
   {
      JFrame f = new JFrame("Test2");
      f.setContentPane(new test1());
      f.setBounds( 10,10,300,200);
      f.show();
   }

   public test1()
   {
      JButton b = new JButton("Show Palette");
      setLayout( new BorderLayout() );

      iFrame.setDefaultCloseOperation(iFrame.HIDE_ON_CLOSE);
      iFrame.setResizable(true);
      iFrame.setClosable(true);

      add( new Desktop(), BorderLayout.CENTER );
	   add( b, BorderLayout.SOUTH );
      
      b.addActionListener( new ActionListener() {
         public void actionPerformed( ActionEvent ev )
         {
            iFrame.show();
         }
      });
   }
   
   private class Desktop extends JDesktopPane
   {
      public Desktop()
      {
         pane.setText( "this is a test this is a test this is a test this is a test this is a test this is a test "
                      + "this is a test this is a test this is a test this is a test this is a test this is a test "
                      + "this is a test this is a test this is a test this is a test this is a test this is a test ");
         
         
   	   add( pane, new Integer(1) );
   	   add( iFrame, this.PALETTE_LAYER );
   	   
   	   iFrame.setBounds(150, 25, 100,100 );
   	}
   }
   
	public Dimension getPreferredSize()
	{
	   return pane.getPreferredSize();
	}
	
	public Dimension getMinimumSize()
	{
	   return pane.getMinimumSize();
	}

   public void setBounds( int x, int y, int w, int h )
   {
      Insets insets = getInsets();

      super.setBounds( x, y, w, h );

      if( (w==0) || (h==0) ) return;
      
      pane.setBounds( x+insets.left, y+insets.top, w-(insets.left+insets.right), h-(insets.top+insets.bottom) );
   }
	   
}
(Review ID: 133946) 
======================================================================

Comments
EVALUATION Actually the reason this happened in previous versions of the jdk is because focus was lost. The user then has to click a component to restore focus. This is not a regression since even under 1.3 the user loses the text selection when the button is pressed to bring the palette up. The only problem I see is that the cursor is not restored to the position it was at after the palette is closed. Dropping priority and removing regression keyword. ###@###.### 2001-10-22 The CloseAction is activated on mouse released which comes before a mouse click. Since the internal frame is closed the mouse click seems to mistakenly go to the pane. ###@###.### 2001-11-12 This is due to a bug in MouseEvent which is fixed in merlin-rc1. Closing as a duplicate of 4508327. ###@###.### 2001-11-15
12-11-2001