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

Cannot set background color of JInternalFrame in Swing 0.6; could in 0.5.1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.2.0
    • client-libs
    • swing0.7
    • generic
    • generic
    • Verified


      The following application demonstrates that in Swing 0.6, the background
      color of JInternalFrame cannot be set. This feature does work with
      Swing 0.5.1.

      Start the application and press the "Show Internal Frame" button. Each
      internal frame that is shown is expected to have a colored background.
      With Swing 0.5.1, this does happen; with Swing 0.6 it does not.

      /*=========================================================================*/
      /*
       * JInternalFrameColorBug.java
       * Cannot set the background color of a JInternalFrame.
       *
       */

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

      public class JInternalFrameColorBug 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 JInternalFrameColorBug();
         }

         public JInternalFrameColorBug() {
            JFrame frame = new JFrame("JInternalFrame Test");
            JPanel controlPanel = new JPanel();
            JButton showButton = new JButton("Show Internal Frame");

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

            controlPanel.add(showButton);
            frame.add(BorderLayout.NORTH, controlPanel);
            frame.add(BorderLayout.CENTER, dpane);

            showButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
      String command = evt.getActionCommand();
                if (command == "Show Internal Frame")
                  showInternalFrame();
      }
            });

            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 showInternalFrame() {
            internalFrame = new JInternalFrame("JInternalFrame");
            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++;
         }

      }
      /*=========================================================================*/

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: