Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4116835

JInternalFrame.setVisible(true) causes StackOverflowError (infinite loop)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      swing1.1
    • CPU:
      generic, x86
    • OS:
      generic, windows_95
    • Verification:
      Verified

      Description


      Invoking JInternalFrame.setVisible(true) causes a StackOverflowError:

      Exception occurred during event dispatching:
      java.lang.StackOverflowError
              at sun.awt.AppContext.getAppContext(AppContext.java:129)
              at java.awt.swing.SwingUtilities.appContextGet(SwingUtilities.java:1330)
              at java.awt.swing.RepaintManager.currentManager(RepaintManager.java:50)
              at java.awt.swing.JComponent.repaint(JComponent.java:2873)
              at java.awt.Component.repaint(Component.java:1543)
              at java.awt.Component.reshape(Component.java:1055)
              at java.awt.swing.JComponent.reshape(JComponent.java:2304)
              at java.awt.Component.setBounds(Component.java:1039)
              at java.awt.swing.plaf.basic.BasicInternalFrameUI.layoutContainer(BasicInternalFrameUI.java:370)
              at java.awt.Container.layout(Container.java:462)
              at java.awt.Container.doLayout(Container.java:452)
              at java.awt.Container.validateTree(Container.java:523)
              at java.awt.Container.validate(Container.java:505)
              at java.awt.swing.JInternalFrame.reshape(JInternalFrame.java:887)
              at java.awt.Component.setBounds(Component.java:1039)
              at java.awt.Component.resize(Component.java:976)
              at java.awt.Component.setSize(Component.java:968)
              at java.awt.Component.resize(Component.java:997)
              at java.awt.Component.setSize(Component.java:989)
              at java.awt.swing.JInternalFrame.pack(JInternalFrame.java:1047)
              at java.awt.swing.JInternalFrame.show(JInternalFrame.java:1062)
              at java.awt.Component.show(Component.java:636)
              at java.awt.Component.setVisible(Component.java:598)
              at java.awt.swing.JComponent.setVisible(JComponent.java:1168)
              at java.awt.swing.JInternalFrame.setVisible(JInternalFrame.java:458)
              at java.awt.swing.JInternalFrame.show(JInternalFrame.java:1064)
              at java.awt.Component.show(Component.java:636)
              at java.awt.Component.setVisible(Component.java:598)
              at java.awt.swing.JComponent.setVisible(JComponent.java:1168)
              at java.awt.swing.JInternalFrame.setVisible(JInternalFrame.java:458)
              at java.awt.swing.JInternalFrame.show(JInternalFrame.java:1064)
        (and so on, to infinity)


      The following application demonstrates this.
      To recreate, bring up the app and click on the "Create Internal Frame" button.
      Then click on the "Invoke JInternalFrame.setVisible(false)" button.
      Then click on the "Invoke JInternalFrame.setVisible(true)" button.

      =============================================================================
      /*
       * stackOverflow.java
       * Invoking JInternalFrame.setVisible(true) causes StackOverflowError
       *
       */

      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.event.*;
      import java.awt.swing.*;

      public class stackOverflow extends JPanel {
         JInternalFrame internalFrame;
         int layer = 0;
         int frameCount = 0;
         JDesktopPane dpane = new JDesktopPane();
         Color[] colors = {Color.blue, Color.green, Color.red, Color.yellow,
      Color.magenta};

         public static void main( String[] argv ) {
           new stackOverflow();
         }

         public stackOverflow() {
            JFrame frame = new JFrame("JInternalFrame Test");
            JPanel controlPanel = new JPanel();
            JButton createButton = new JButton("Create Internal Frame");
            JButton setVisibleButton = new JButton("Invoke JInternalFrame.setVisible(false)");

            frame.getContentPane().setLayout(new BorderLayout());
            frame.setBackground(Color.white);
            dpane.setOpaque(true);
            dpane.setBackground(Color.pink);

            createButton.setPreferredSize(new Dimension(305,25));
            controlPanel.add(createButton);
            frame.getContentPane().add(BorderLayout.NORTH, controlPanel);
            frame.getContentPane().add(BorderLayout.CENTER, dpane);

            createButton.addActionListener(new listener1());
            setVisibleButton.addActionListener(new listener1());

            frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {System.exit(0);}
              public void windowClosed(WindowEvent e) {System.exit(0);}
            });

            frame.pack();
            frame.setSize(500, 400);
            frame.setVisible(true);
         }

         public void createInternalFrame() {
            internalFrame = new JInternalFrame("JInternalFrame", true, true, true, true);
            internalFrame.setBackground(colors[frameCount]);
            frameCount++;
            internalFrame.setBounds(20*frameCount, 20*frameCount, 150, 200);

            if (frameCount > 4)
      frameCount = 0;

            dpane.add(internalFrame, new Integer(layer));
            try {internalFrame.setSelected(true);} catch
                                      (java.beans.PropertyVetoException e) {}
            layer++;
         }

         class listener1 implements ActionListener {
           public void actionPerformed(ActionEvent evt) {
             String command = evt.getActionCommand();
             if (command == "Create Internal Frame") {
               createInternalFrame();
               ((JButton)(evt.getSource())).setText("Invoke JInternalFrame.setVisible(false)");
             }
             else if (command == "Invoke JInternalFrame.setVisible(false)") {
               internalFrame.setVisible(false);
               ((JButton)(evt.getSource())).setText("Invoke JInternalFrame.setVisible(true)");
             }
             else if (command == "Invoke JInternalFrame.setVisible(true)") {
               internalFrame.setVisible(true);
             }
           }
         }

      }
      =============================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tballsunw Tom Ball (Inactive)
              Reporter:
              gaurisha Gauri Sharma (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: