// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import java.awt.geom.Path2D;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    add(new JScrollPane(new JTextArea()));
    setPreferredSize(new Dimension(320, 240));
  }

  private static JMenu makeSubMenu(String title) {
    JMenu menu = new JMenu(title);
    menu.add("Item 1");
    menu.add("Item 2");
    menu.add("Item 3");
    // // NimbusLookAndFeel
    // UIDefaults d = new UIDefaults();
    // d.put("Menu.arrowIcon", new ArrowIcon());
    // menu.putClientProperty("Nimbus.Overrides", d);
    // menu.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
    return menu;
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      // // NimbusLookAndFeel
      // UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
      // UIManager.getLookAndFeelDefaults().put("Menu.arrowIcon", new ArrowIcon());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new JMenu("Menu 1")).add(makeSubMenu("SubMenu 1"));
    UIManager.put("Menu.arrowIcon", new ArrowIcon());
    menuBar.add(new JMenu("Menu 2")).add(makeSubMenu("SubMenu 2"));

    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

class ArrowIcon implements Icon {
  @Override public void paintIcon(Component c, Graphics g, int x, int y) {
    // // NimbusLookAndFeel
    // Container parent = SwingUtilities.getUnwrappedParent(c);
    // if (parent instanceof JMenuBar) {
    //   return;
    // }

    Graphics2D g2 = (Graphics2D) g.create();
    if (c instanceof AbstractButton && ((AbstractButton) c).getModel().isSelected()) {
      g2.setPaint(Color.WHITE);
    } else {
      g2.setPaint(Color.GRAY);
    }

    int w = getIconWidth() / 2;
    Path2D p = new Path2D.Double();
    p.moveTo(0, 0);
    p.lineTo(w, w);
    p.lineTo(0, getIconHeight());
    p.closePath();

    g2.translate(x, y);
    g2.fill(p);
    g2.dispose();
  }

  @Override public int getIconWidth() {
    return 8;
  }

  @Override public int getIconHeight() {
    return 8;
  }
}

@@ -262,24 +262,346 @@
 rLayout());%0A
+    EventQueue.invokeLater(() -%3E %7B%0A      JMenuBar menuBar = new JMenuBar();%0A      menuBar.add(new JMenu(%22Menu 1%22)).add(makeSubMenu(%22SubMenu 1%22));%0A      UIManager.put(%22Menu.arrowIcon%22, new ArrowIcon());%0A      menuBar.add(new JMenu(%22Menu 2%22)).add(makeSubMenu(%22SubMenu 2%22));%0A      getRootPane().setJMenuBar(menuBar);%0A    %7D);%0A
     add(new 
@@ -627,24 +627,24 @@
 xtArea()));%0A
-
     setPrefe
@@ -1740,239 +1740,8 @@
   %7D%0A
-%0A    JMenuBar menuBar = new JMenuBar();%0A    menuBar.add(new JMenu(%22Menu 1%22)).add(makeSubMenu(%22SubMenu 1%22));%0A    UIManager.put(%22Menu.arrowIcon%22, new ArrowIcon());%0A    menuBar.add(new JMenu(%22Menu 2%22)).add(makeSubMenu(%22SubMenu 2%22));%0A%0A
     
@@ -1898,40 +1898,8 @@
 ));%0A
-    frame.setJMenuBar(menuBar);%0A
     
@@ -2474,19 +2474,22 @@
  %7D%0A%0A    
-int
+double
  w = get
@@ -2503,16 +2503,17 @@
 th() / 2
+d
 ;%0A    Pa
@@ -2560,11 +2560,13 @@
 To(0
+d
 , 0
+d
 );%0A 
@@ -2584,16 +2584,16 @@
 (w, w);%0A
-
     p.li
@@ -2598,16 +2598,17 @@
 lineTo(0
+d
 , getIco

use JRootPane#setJMenuBar(...) instead of JFrame#setJMenuBar(...)