package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;

public final class MainPanel extends JPanel {
    private final JTextField field1 = new JTextField("Please enter your E-mail address");
    private final JTextField field2 = new JTextField("History Search");
    public MainPanel() {
        super(new BorderLayout());
        field1.addFocusListener(new PlaceholderFocusListener(field1));
        field2.addFocusListener(new PlaceholderFocusListener(field2));

        Box box = Box.createVerticalBox();
        box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        box.add(makePanel("E-mail", field1));
        box.add(Box.createVerticalStrut(5));
        box.add(makePanel("Search", field2));

        add(box, BorderLayout.NORTH);
        setPreferredSize(new Dimension(320, 240));
    }
    private static JPanel makePanel(String title, JComponent c) {
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createTitledBorder(title));
        p.add(c);
        return p;
    }
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException |
                 IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class PlaceholderFocusListener implements FocusListener {
    private static final Color INACTIVE = UIManager.getColor("TextField.inactiveForeground");
    private final String hintMessage;
    public PlaceholderFocusListener(JTextComponent tf) {
        hintMessage = tf.getText();
        tf.setForeground(INACTIVE);
    }
    @Override public void focusGained(FocusEvent e) {
        JTextComponent tf = (JTextComponent) e.getComponent();
        if (hintMessage.equals(tf.getText()) && INACTIVE.equals(tf.getForeground())) {
            tf.setForeground(UIManager.getColor("TextField.foreground"));
            tf.setText("");
        }
    }
    @Override public void focusLost(FocusEvent e) {
        JTextComponent tf = (JTextComponent) e.getComponent();
        if ("".equals(tf.getText().trim())) {
            tf.setForeground(INACTIVE);
            tf.setText(hintMessage);
        }
    }
}

@@ -145,23 +145,74 @@
 ort java
-x.swing
+.awt.font.*;%0Aimport javax.swing.*;%0Aimport javax.swing.plaf
 .*;%0Aimpo
@@ -439,24 +439,80 @@
 y Search%22);%0A
+    private final JTextField field3 = new JTextField();%0A
     public M
@@ -899,17 +899,18 @@
 alStrut(
-5
+10
 ));%0A    
@@ -942,32 +942,194 @@
 arch%22, field2));
+%0A        box.add(Box.createVerticalStrut(10));%0A        box.add(makePanel(%22JLayer%22, new JLayer%3CJTextComponent%3E(field3, new PlaceholderLayerUI(%22JLayer version%22))));
 %0A%0A        add(bo
@@ -3134,16 +3134,1395 @@
       %7D%0A    %7D%0A%7D%0A
+%0Aclass PlaceholderLayerUI extends LayerUI%3CJTextComponent%3E %7B%0A    private static final Color INACTIVE = UIManager.getColor(%22TextField.inactiveForeground%22);%0A//     private final String hintMessage;%0A    private final JLabel hint;%0A    public PlaceholderLayerUI(String hintMessage) %7B%0A        super();%0A        this.hint = new JLabel(hintMessage);%0A        hint.setForeground(INACTIVE);%0A    %7D%0A    @Override public void paint(Graphics g, JComponent c) %7B%0A        super.paint(g, c);%0A        if (c instanceof JLayer) %7B%0A            JLayer jlayer = (JLayer) c;%0A            JTextComponent tc = (JTextComponent) jlayer.getView();%0A            if (tc.getText().length() == 0 && !tc.hasFocus()) %7B%0A                Graphics2D g2 = (Graphics2D) g.create();%0A                g2.setPaint(INACTIVE);%0A                Insets i = tc.getInsets();%0A                Dimension d = hint.getPreferredSize();%0A                SwingUtilities.paintComponent(g2, hint, tc, i.left, i.top, d.width, d.height);%0A//                 int baseline = tc.getBaseline(tc.getWidth(), tc.getHeight());%0A//                 Font font = tc.getFont();%0A//                 FontRenderContext frc = g2.getFontRenderContext();%0A//                 TextLayout tl = new TextLayout(hintMessage, font, frc);%0A//                 tl.draw(g2, i.left + 2, baseline);%0A                g2.dispose();%0A            %7D%0A            tc.repaint();%0A        %7D%0A    %7D%0A%7D%0A

add JLayer demo