JDK-4172978 : Bad layout of JDesktopPane with maximized JInternalFrame
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-09-11
  • Updated: 1998-11-20
  • Resolved: 1998-11-20
Related Reports
Duplicate :  
Description

Name: diC59631			Date: 09/11/98


import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
  Title:   Bad layout of JDesktopPane with maximized JInternalFrame
  
  Description: 
    Resizing a JFrame that contains a JDesktopPane (below
    or to the right of another component) that contains a
    maximized JInternalFrame causes the JDesktopPane's
    location to be set to (0,0).
 */

public class DesktopPaneLayoutBug extends JFrame
{
  public DesktopPaneLayoutBug()
  {
    Dimension screenSize = getToolkit().getScreenSize();

    setBounds (screenSize.width / 4,  screenSize.height / 4,
               screenSize.width / 2,  screenSize.height / 2);
    
    addWindowListener (new WindowAdapter() {
      public void windowClosing (WindowEvent event)
      {
        System.exit(0);
      }
    });
  } // constructor
  
  static public void main(String args[])
  {
    JFrame     mainFrame   = new DesktopPaneLayoutBug();
    Container  mainContent = mainFrame.getContentPane();
    JButton    showBounds  = new JButton ("Show Desktop Bounds");
    JInternalFrame textFrame = new JInternalFrame ("Test", true, true, true, true);

    textFrame.getContentPane().add (new JScrollPane (textArea));
    desktop.add (textFrame);

    showBounds.addActionListener (new ActionListener()
      {
        public void actionPerformed (ActionEvent e)
        {
          textArea.append ("Desktop bounds = " + desktop.getBounds() + "\n");
        }
      });
    
    mainContent.add (showBounds, BorderLayout.NORTH);
    mainContent.add (desktop,    BorderLayout.CENTER);

    mainFrame.show();
    
    textFrame.show();
    try {
      textFrame.setMaximum (true);
    } catch (java.beans.PropertyVetoException e) {}
  } // main

  static private JDesktopPane desktop  = new JDesktopPane();
  static private JTextArea    textArea = new JTextArea ("Resize the JFrame and watch the JDesktopPane jump under the JButton\n");
} // DesktopPaneLayoutBug
(Review ID: 38627)
======================================================================

Comments
WORK AROUND /** * 4172978: workaround for problem with a maximized JInternalFrame not * tracking parent frame size changes. */ import javax.swing.*; import javax.swing.plaf.*; import java.awt.*; import java.awt.event.*; import java.beans.*; // Substitute other L&F class if necessary, such as WindowsInternalFrameUI. import javax.swing.plaf.metal.MetalInternalFrameUI; public class InternalFrameTest extends JFrame { InternalFrameTest() { /* * Create a frame which has a desktop pane with a single internal frame. */ super("JInternalFrame test"); JDesktopPane jdp = new JDesktopPane(); getContentPane().add("Center", jdp); JInternalFrame jframe = new JInternalFrame("Test", true, true, true, true); jframe.setSize(150, 100); jdp.add(jframe, JLayeredPane.PALETTE_LAYER); setSize(500, 400); validate(); } /** * Override MetalInternalFrameUI to fix how it tracks the size of its * desktop pane when maximized. What's needed is a ComponentListener * which tracks componentResized events, but there's a complication in * that when the UI is being installed, its associated internal frame * usually doesn't have a desktop pane yet. Watch PropertyChangeEvents * will give us a chance to add the listener before the app is realized. */ public static class MyInternalFrameUI extends MetalInternalFrameUI implements PropertyChangeListener { public static ComponentUI createUI(JComponent b) { return new MyInternalFrameUI((JInternalFrame)b); } JInternalFrame frame = null; boolean listenerAdded = false; public MyInternalFrameUI(JInternalFrame jif) { super(jif); frame = jif; jif.addPropertyChangeListener(this); } // PropertyChanges are watched so that the ComponentListener can be // added as soon as there's a desktop pane to listen to. public void propertyChange(PropertyChangeEvent evt) { JDesktopPane desktop = frame.getDesktopPane(); if (!listenerAdded && desktop != null) { desktop.addComponentListener(new ComponentAdapter() { // Track the desktop pane's size when frame is maximized. public void componentResized(ComponentEvent e) { if (frame.isMaximum()) { Dimension d = ((Component)e.getSource()).getSize(); frame.setBounds(0, 0, d.width, d.height); frame.validate(); } } }); listenerAdded = true; } } } public static void main(String[] args) { // Override the MetalInternalFrameUI with one with a fixed // componentResized method. UIManager.getLookAndFeel(); // force L&F to initialize UIManager.put("InternalFrameUI", "InternalFrameTest$MyInternalFrameUI"); JFrame frame = new InternalFrameTest(); frame.show(); } }
11-06-2004

PUBLIC COMMENTS .
10-06-2004

EVALUATION i'm not able to reproduce this with the latest swing-2.0 workspace. the x/y of the desktoppane are correct after a resize. it is occuring with the latest jdk1.2fcs (which is code frozen). the fix is putback into swing-2.0 and I suspect it is the BasicInternalFrameUI code recently changed. richard.schiavi@Eng 1998-10-12
12-10-1998