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

package example;

import java.awt.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;

public final class MainPanel extends JPanel {
  private static final String DUMMY_TEXT = "Quartz glyph job vex'd cwm finks.";

  private MainPanel() {
    super(new GridLayout(3, 1));

    JTextPane label1 = new JTextPane();
    // MutableAttributeSet attr = new SimpleAttributeSet();
    Style attr = label1.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setLineSpacing(attr, -.2f);
    label1.setParagraphAttributes(attr, true);
    label1.setText("JTextPane\n" + DUMMY_TEXT);
    // [XP Style Icons - Download](https://xp-style-icons.en.softonic.com/)
    ImageIcon icon = new ImageIcon(getClass().getResource("wi0124-32.png"));
    add(makeLeftIcon(label1, icon));

    JTextArea label2 = new JTextArea("JTextArea\n" + DUMMY_TEXT);
    add(makeLeftIcon(label2, icon));

    JLabel label3 = new JLabel("<html>JLabel+html<br>" + DUMMY_TEXT);
    label3.setIcon(icon);
    add(label3);

    setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    setPreferredSize(new Dimension(320, 240));
  }

  private static Box makeLeftIcon(JTextComponent label, ImageIcon icon) {
    label.setForeground(UIManager.getColor("Label.foreground"));
    // label.setBackground(UIManager.getColor("Label.background"));
    label.setOpaque(false);
    label.setEditable(false);
    label.setFocusable(false);
    label.setMaximumSize(label.getPreferredSize());
    label.setMinimumSize(label.getPreferredSize());

    JLabel l = new JLabel(icon);
    l.setCursor(Cursor.getDefaultCursor());
    Box box = Box.createHorizontalBox();
    box.add(l);
    box.add(Box.createHorizontalStrut(2));
    box.add(label);
    box.add(Box.createHorizontalGlue());
    return box;
  }

  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();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

@@ -109,24 +109,137 @@
 java.awt.*;%0A
+import java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Optional;%0Aimport javax.imageio.ImageIO;%0A
 import javax
@@ -474,22 +474,16 @@
  String 
-DUMMY_
 TEXT = %22
@@ -572,25 +572,24 @@
 out(3, 1));%0A
-%0A
     JTextPan
@@ -863,30 +863,24 @@
 xtPane%5Cn%22 + 
-DUMMY_
 TEXT);%0A    /
@@ -958,76 +958,442 @@
     
-ImageIcon icon = new ImageIcon(getClass().getResource(%22wi0124-32.png
+String path = %22example/wi0124-32.png%22;%0A    ClassLoader cl = Thread.currentThread().getContextClassLoader();%0A    Icon icon = Optional.ofNullable(cl.getResource(path)).map(url -%3E %7B%0A      try (InputStream s = url.openStream()) %7B%0A        return new ImageIcon(ImageIO.read(s));%0A      %7D catch (IOException ex) %7B%0A        return UIManager.getIcon(%22OptionPane.errorIcon%22);%0A      %7D%0A    %7D).orElseGet(() -%3E UIManager.getIcon(%22OptionPane.errorIcon
 %22));
@@ -1480,30 +1480,24 @@
 xtArea%5Cn%22 + 
-DUMMY_
 TEXT);%0A    a
@@ -1590,14 +1590,8 @@
 %22 + 
-DUMMY_
 TEXT
@@ -1805,21 +1805,16 @@
  label, 
-Image
 Icon ico

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