import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.TextArea;
import java.awt.TextField;
import javax.swing.BoxLayout;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class ZeroWidthNonJoinerCharCannotBeEntered {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame("ZeroWidthNonJoinerCharCannotBeEntered");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                Container content = frame.getContentPane();
                content.setLayout(new BorderLayout());

                JPanel awtCompsPanel = new JPanel();
                awtCompsPanel.setLayout(new BoxLayout(awtCompsPanel, BoxLayout.Y_AXIS));
                content.add(awtCompsPanel, BorderLayout.WEST);

                JLabel awtCompsPanelHdrLbl = new JLabel("AWT Text Components");
                Font hdrFont = new Font(Font.SANS_SERIF, Font.BOLD, 14);
                awtCompsPanelHdrLbl.setFont(hdrFont);
                awtCompsPanel.add(createFlowLayoutPanelWithComp(awtCompsPanelHdrLbl));
                awtCompsPanel.add(createFlowLayoutPanelWithComp(new JLabel("TextField")));
                awtCompsPanel.add(createFlowLayoutPanelWithComp(new TextField(30)));
                awtCompsPanel.add(createFlowLayoutPanelWithComp(new JLabel("TextArea")));
                awtCompsPanel.add(createFlowLayoutPanelWithComp(new TextArea(5, 30)));

                JPanel swingCompsPanel = new JPanel();
                swingCompsPanel.setLayout(new BoxLayout(swingCompsPanel, BoxLayout.Y_AXIS));
                content.add(swingCompsPanel, BorderLayout.CENTER);

                JLabel swingCompsPanelHdrLbl = new JLabel("Swing Text Components");
                swingCompsPanelHdrLbl.setFont(hdrFont);
                swingCompsPanel.add(createFlowLayoutPanelWithComp(swingCompsPanelHdrLbl));
                swingCompsPanel.add(createFlowLayoutPanelWithComp(new JLabel("JTextField")));
                swingCompsPanel.add(createFlowLayoutPanelWithComp(new JTextField(30)));
                swingCompsPanel.add(createFlowLayoutPanelWithComp(new JLabel("JTextArea")));
                JTextArea jTextArea = new JTextArea(5, 30);
                JScrollPane scrollPaneJTA = new JScrollPane(jTextArea,
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                scrollPaneJTA.setPreferredSize(jTextArea.getPreferredSize());
                swingCompsPanel.add(createFlowLayoutPanelWithComp(scrollPaneJTA));
                swingCompsPanel.add(createFlowLayoutPanelWithComp(new JLabel("JEditorPane")));
                JEditorPane jEditorPane = new JEditorPane("text/plain", "");
                JScrollPane scrollPaneJEP = new JScrollPane(jEditorPane,
                        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
                scrollPaneJEP.setPreferredSize(new Dimension(200, 100));
                swingCompsPanel.add(createFlowLayoutPanelWithComp(scrollPaneJEP));

                frame.pack();
                frame.setVisible(true);
            }
        });
    }

    private static JPanel createFlowLayoutPanelWithComp(Component comp) {
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        if (comp != null) {
            panel.add(comp);
        }
        return panel;
    }
}
