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

setFont() does not update Fonts of Menus already on screen

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b01
    • CPU:
      generic
    • OS:
      generic

      Backports

        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());
                        }
        */
                    }
                }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                serb Sergey Bylokhov
                Reporter:
                bchristi Brent Christian
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: