JDK-4717864 : setFont() does not update Fonts of Menus already on screen
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.1,6,7,8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-07-19
  • Updated: 2017-10-04
  • Resolved: 2011-08-03
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.
JDK 6 JDK 7 JDK 8 Other
6u151Fixed 7u141Fixed 8 b01Fixed openjdk7uFixed
Related Reports
Relates :  
Description
MenuComponent.setFont() works correctly if it is called before Menus are shown on screen.  Calling setFont() on Menus that are already showing on screen does not update the Font.

This has been the case for quite some time now.

The following test case can be used to demonstrate the problem on top-level Menus.
------------------
import java.awt.*;
import java.awt.event.*;

public class MenuTest {
        private static Font bigFont = new Font("Dialog", Font.PLAIN, 48);
        private static Font smallFont = new Font("Dialog", Font.PLAIN, 18);

        public static void main(String[] args) {
                Frame f = new Frame("MenuTest 1");
                MenuBar mb = new MenuBar();

                mb.setFont(bigFont);

                mb.add(createMenu("Big Menu with really long title", bigFont));
                mb.add(createMenu("Small Menu", smallFont));
                mb.add(createMenu("Normal Menu", null));
                f.setMenuBar(mb);
                //f.pack();
                f.setSize(600, 600);
                f.setVisible(true);


        }

        private static Menu createMenu(String name, Font font) {
                Menu m = new Menu(name);
                m.setFont(font);
                for (int i = 0; i < 5; i++) {
                        m.add(new MenuItem("MenuItem " + i));
                }

                m.add(new MenuActionListener("Set Big Font", bigFont));
                m.add(new MenuActionListener("Set Small Font", smallFont));

                return m;
        }

        private static class MenuActionListener extends MenuItem implements ActionListener {
            private Font font;
            public MenuActionListener(String name, Font f) {
                super(name);
                font = f;
                addActionListener(this);
            }
            public void actionPerformed(ActionEvent e) {
                MenuContainer mc = getParent();
                if (mc instanceof MenuComponent) {
                    ((MenuComponent)mc).setFont(font);
                }
		/* work-around
                if (mc instanceof MenuItem) {
                    ((MenuItem)mc).setLabel(((MenuItem)mc).getLabel());
                }
		*/
            }
        }
}

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/awt_data/8/4717864/
15-07-2011

EVALUATION Reproduced on java2d-01.russia.sun.com - windows xp sp3 with jdk 7b146
22-06-2011

WORK AROUND Set Menu Fonts before they are displayed. On Windows, calling setLabel() will update a Menu which is displayed. ###@###.### 2002-07-19
19-07-2002