JDK-4850369 : JInternalFrame setDefaultCloseOperation ignored under Motif look-and-feel.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1_06,1.4.1,1.4.1_02,1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8,windows_2000
  • CPU: x86,sparc
  • Submitted: 2003-04-17
  • Updated: 2003-08-29
  • Resolved: 2003-06-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1_05 05Fixed
Description

Name: jk109818			Date: 04/17/2003


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)


FULL OS VERSION :
Problem is OS-independent. I reproduced it under Windows XP and Solaris 8

A DESCRIPTION OF THE PROBLEM :
The method "setDefaultCloseOperation()" of JInternalFrame is ignored under Motif Look-and-feel. My attached testcase demonstrates the problem.

I set the default close operation of a JInternalFrame to "DO_NOTHING_ON_CLOSE", but it is not honored under Motif look-and-feel.

My application that works under Windows L&F and Metal L&F, does not work properly
under Motif because of this problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and execute the source code of my test case. Double click the upper left corner of the internal frame.

EXPECTED VERSUS ACTUAL BEHAVIOR :
The expected results is that the double click of the close button of the
internal frame be ignored.
The double-clicking of the close button causes the internal frame to close, even though the default close operation was set to "DO_NOTHING_ON_CLOSE".

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.event.*;

/**
 * Demonstrates bug:
 * "setDefaultCloseOperation()" ignored for JInternalFrame under Motif.
 */
class Test {

    public static void main(String args[]){
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        }
        catch(Exception x){
            System.err.println("Can't switch to Motif Look and Feel");
            System.exit(1);
        }

        JFrame f = new JFrame("Test");
        JDesktopPane pane = new JDesktopPane();
        f.setContentPane(pane);
        JInternalFrame iframe = new JInternalFrame("InternalFrame");
        iframe.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
        iframe.addInternalFrameListener(new InternalFrameAdapter(){
             public void internalFrameClosed(InternalFrameEvent e){
                 System.err.println("Hey! Not suppose to close!!!");
                 }
             });
        iframe.setClosable(true);

        iframe.setSize(300,300);
        iframe.show();

        pane.add(iframe);
        f.setSize(500,500);
        f.show();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The only work-around that I know of is to veto the "closed" property change on the  JInternalFrame.

The cause of the bug can be readily seen in the source to:

com.sun.java.swing.plaf.motif.MotifInternalFrameTitlePane

Look for:

        systemButton.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                                if ((e.getClickCount() == 2)){
                                        if (iFrame.isClosable()) {
                                                try{
                                                        iFrame.setClosed(true);
                                                } catch (PropertyVetoException e0) { }
                                        }
                                        systemMenu.setVisible(false);
                                }
                        }
                });


Change the statement "iFrame.setClosed(true)" to
"iFrame.doDefaultCloseAction()".
(Review ID: 184329) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.1_05 1.4.2_02 tiger FIXED IN: 1.4.1_05 1.4.2_02 tiger INTEGRATED IN: 1.4.1_05 1.4.2_02 tiger tiger-b19 VERIFIED IN: 1.4.1_05
2004-06-14

SUGGESTED FIX ------- MotifInternalFrameTitlePane.java ------- *** /tmp/sccs.741xNf Thu May 22 10:11:40 2003 --- src/share/classes/com/sun/java/swing/plaf/motif/MotifInternalFrameTitlePane.java Thu Apr 24 12:43:34 2003 *************** *** 88,99 **** systemButton.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if ((e.getClickCount() == 2)){ ! if (frame.isClosable()) { ! try { ! frame.setClosed(true); ! } catch (PropertyVetoException e0) { ! } ! } systemMenu.setVisible(false); } } --- 88,94 ---- systemButton.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if ((e.getClickCount() == 2)){ ! frame.doDefaultCloseAction(); systemMenu.setVisible(false); } } ###@###.### 2003-05-22 Fix integrated in 1.4.1_04 ###@###.### 2003-05-30
2003-05-22

EVALUATION The mouse listener on the system button should be calling the doDefaultCloseOperation and not setClosed. ###@###.### 2003-04-24 Shannon had a better idea to have it use CloseAction instead. Now if developers subclass CloseAction we will pick up their changes. ###@###.### 2003-08-29
2003-04-24