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

package example;

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

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    EventQueue.invokeLater(() -> getRootPane().setJMenuBar(createMenuBar()));
    add(new JLabel(new ImageIcon(getClass().getResource("test.png"))));
    setPreferredSize(new Dimension(320, 240));
  }

  private static JMenuBar createMenuBar() {
    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("File");
    mb.add(menu);
    menu.add("Open");
    menu.add("Save");
    menu.add("Close");
    menu.add("Exit");
    menu = new JMenu("Edit");
    mb.add(menu);
    menu.add("Cut");
    menu.add("Copy");
    menu.add("Paste");
    JMenu smenu = new JMenu("Edit");
    smenu.add("Cut");
    smenu.add("Copy");
    smenu.add("Paste");
    menu.add(smenu);
    return mb;
  }

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

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    UIManager.put("PopupMenuUI", "example.CustomPopupMenuUI");
    // contrib.com.jgoodies.looks.common.ShadowPopupFactory.install();

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

@@ -113,16 +113,166 @@
 .awt.*;%0A
+import java.awt.image.BufferedImage;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Optional;%0Aimport javax.imageio.ImageIO;%0A
 import j
@@ -473,71 +473,425 @@
     
-add(new JLabel(new ImageIcon(getClass().getResource(%22test.png%22)
+String path = %22example/16x16.png%22;%0A    ClassLoader cl = Thread.currentThread().getContextClassLoader();%0A    Image image = Optional.ofNullable(cl.getResource(path)).map(url -%3E %7B%0A      try (InputStream s = url.openStream()) %7B%0A        return ImageIO.read(s);%0A      %7D catch (IOException ex) %7B%0A        return makeMissingImage();%0A      %7D%0A    %7D).orElseGet(MainPanel::makeMissingImage);%0A    add(new JLabel(new ImageIcon(image
 )));
@@ -1289,20 +1289,18 @@
  JMenu s
-men
 u
+b
  = new J
@@ -1314,28 +1314,26 @@
 dit%22);%0A    s
-men
 u
+b
 .add(%22Cut%22);
@@ -1334,28 +1334,26 @@
 Cut%22);%0A    s
-men
 u
+b
 .add(%22Copy%22)
@@ -1359,20 +1359,18 @@
 );%0A    s
-men
 u
+b
 .add(%22Pa
@@ -1390,20 +1390,384 @@
 nu.add(s
-menu
+ub);%0A    return mb;%0A  %7D%0A%0A  private static Image makeMissingImage() %7B%0A    Icon missingIcon = new MissingIcon();%0A    int w = missingIcon.getIconWidth();%0A    int h = missingIcon.getIconHeight();%0A    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);%0A    Graphics2D g2 = bi.createGraphics();%0A    missingIcon.paintIcon(null, g2, 0, 0);%0A    g2.dispose(
 );%0A    r
@@ -1764,34 +1764,34 @@
 e();%0A    return 
-m
 b
+i
 ;%0A  %7D%0A%0A  public 
@@ -2600,8 +2600,646 @@
 ;%0A  %7D%0A%7D%0A
+%0Aclass MissingIcon implements Icon %7B%0A  @Override public void paintIcon(Component c, Graphics g, int x, int y) %7B%0A    Graphics2D g2 = (Graphics2D) g.create();%0A%0A    int w = getIconWidth();%0A    int h = getIconHeight();%0A    int gap = w / 5;%0A%0A    g2.setColor(Color.WHITE);%0A    g2.fillRect(x, y, w, h);%0A%0A    g2.setColor(Color.RED);%0A    g2.setStroke(new BasicStroke(w / 8f));%0A    g2.drawLine(x + gap, y + gap, x + w - gap, y + h - gap);%0A    g2.drawLine(x + gap, y + h - gap, x + w - gap, y + gap);%0A%0A    g2.dispose();%0A  %7D%0A%0A  @Override public int getIconWidth() %7B%0A    return 320;%0A  %7D%0A%0A  @Override public int getIconHeight() %7B%0A    return 240;%0A  %7D%0A%7D%0A

argument 'getClass().getResource(...)' might be null