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

setFrameIcon of JInternalFrame doesn't work when look and feel is 'Windows'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • client-libs



      Name: yyT116575 Date: 06/15/2001


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

      Section 1: Steps
      ================
      (1) Prepare a small gif file 'script.gif' for the internal fram icon
      (2) Put 'script.gif' along with the class files
      (3) Run the following program on Windows
      (4) The icon of the internal is not 'script.gif'

      Section 2: Source Code
      ======================
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      /**
      * This is a JDK1.4 bug
      *
      * The method setFrameIcon(Icon) of JInternalFrame doesn't work when look and
      feel is 'Windows'
      *
      * The line
      "UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());"
      has to be commented out in order
      * to make the program wrok.
      *
      */

      public class IconBug extends JFrame {
        public static final String ICON_FILE = "script.gif";

        public static void main(String[] args) {
          IconBug bug = new IconBug();
          bug.setVisible(true);
        }

        public IconBug() {
          super("Internal Frame Icon Bug");
          addWindowListener(new FrameWindowListener());
          setBounds(0,0,700,350);

          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          } catch (Exception ex) {
            ex.printStackTrace();
          }

          initMenu();
          initMainPanel();
        }

        private void initMenu() {
          JMenuBar mb = new JMenuBar();
          JMenu me = new JMenu("File");
          JMenuItem mi = new JMenuItem("Exit");

          mi.addActionListener(new MenuActionListener());
          me.add(mi);
          mb.add(me);
          setJMenuBar(mb);
        }

        private void initMainPanel() {
          JPanel main = (JPanel) getContentPane();
          main.setLayout(new BorderLayout());

          // Add a desktop and a internal frame
          JDesktopPane desktop = new JDesktopPane();
          JInternalFrame frame = new MyInternalFrame("Icon is wrong!!!");
          desktop.add(frame);
          frame.setBounds(0,0,300,150);
          main.add(desktop, "Center");
        }

        private void exit() {
          System.exit(0);
        }

        // Inner class
        private class FrameWindowListener extends WindowAdapter {
          public void windowClosing(WindowEvent e) {
            exit();
          }
        }

        // Inner class
        private class MenuActionListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
            exit();
          }
        }

        // Inner class
        private class MyInternalFrame extends JInternalFrame {
          public MyInternalFrame(String title) {
            super(title, true, true, true, true);

            setFrameIcon(new ImageIcon(ICON_FILE));
            setVisible(true);
          }
        }
      }

      (Review ID: 126721)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: