Example usage for javax.swing JEditorPane JEditorPane

List of usage examples for javax.swing JEditorPane JEditorPane

Introduction

In this page you can find the example usage for javax.swing JEditorPane JEditorPane.

Prototype

public JEditorPane() 

Source Link

Document

Creates a new JEditorPane.

Usage

From source file:Main.java

public static void main(String[] args) {
    JEditorPane htmlPane = new JEditorPane();
    String description = "<html><body>Hello<table border=1>"
            + "<tr><td><img alt='Bad' src='http://www.java2s.com/style/download.png'/></tr></td></table></body></html>";
    htmlPane.setContentType("text/html");
    htmlPane.setText(description);//from   w  ww . j  a  va  2 s .  co  m

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(htmlPane));
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JEditorPane jep = new JEditorPane();
    jep.setEditable(false);/*  w w  w. j  ava2  s.c  o m*/

    try {
        jep.setPage("http://www.google.com");
    } catch (IOException e) {
        jep.setContentType("text/html");
        jep.setText("<html>Could not load http://www.google.com </html>");
    }

    JScrollPane scrollPane = new JScrollPane(jep);
    JFrame f = new JFrame();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scrollPane);
    f.setSize(512, 342);
    f.show();

}

From source file:Main.java

public static void main(String[] argv) {
    JEditorPane jep = new JEditorPane();
    jep.setContentType("text/html");
    StringBuilder sb = new StringBuilder();
    sb.append("<b>Welcome</b>:<br><hr>");
    for (int i = 1; i <= 3; i++) {
        sb.append(create(i));//from w w  w  .  ja v  a 2 s .  c o  m
    }
    sb.append("<hr>");
    jep.setText(sb.toString());
    jep.setEditable(false);
    jep.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            System.out.println(e.getURL());
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(e.getURL().toURI());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(jep);
    f.pack();
    f.setVisible(true);
}

From source file:ListActionsJEditorPane.java

public static void main(String args[]) {
    JTextComponent component = new JEditorPane();

    // Process action list
    Action actions[] = component.getActions();
    // Define comparator to sort actions
    Comparator<Action> comparator = new Comparator<Action>() {
        public int compare(Action a1, Action a2) {
            String firstName = (String) a1.getValue(Action.NAME);
            String secondName = (String) a2.getValue(Action.NAME);
            return firstName.compareTo(secondName);
        }//from w  w  w.  j ava  2s.c  o m
    };
    Arrays.sort(actions, comparator);

    int count = actions.length;
    System.out.println("Count: " + count);
    for (int i = 0; i < count; i++) {
        System.out.printf("%28s : %s\n", actions[i].getValue(Action.NAME), actions[i].getClass().getName());
    }
}

From source file:Main.java

License:asdf

public static void main(final String args[]) {
    JFrame frame = new JFrame("EditorPane Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setText("asdf");

    JScrollPane scrollPane = new JScrollPane(editorPane);
    frame.add(scrollPane);//w w w.  jav a  2  s.c  om

    frame.setSize(640, 480);
    frame.setVisible(true);
}

From source file:LoadingWebPageToJEditorPane.java

public static void main(String[] a) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();

    editorPane.setPage(new URL("http://www.java2s.com"));

    frame.add(new JScrollPane(editorPane));

    frame.setSize(300, 200);/*from  w  w  w .  j  a  v  a2  s.  c o  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    JEditorPane edPane = new JEditorPane();
    edPane.setContentType("text/html");

    HTMLEditorKit hek = new HTMLEditorKit();

    edPane.setEditorKit(hek);/*from  w ww .j a va  2 s.  c o m*/

    HTMLDocument doc = (HTMLDocument) edPane.getDocument();

    doc.insertString(0, "Test testing", null);

    Element[] roots = doc.getRootElements();
    Element body = null;
    for (int i = 0; i < roots[0].getElementCount(); i++) {
        Element element = roots[0].getElement(i);
        if (element.getAttributes().getAttribute(StyleConstants.NameAttribute) == HTML.Tag.BODY) {
            body = element;
            break;
        }
    }

    doc.insertAfterEnd(body, "<img src=" + ClassLoader.getSystemResource("thumbnail.png").toString() + ">");
    frame.add(edPane);

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:LoadingHTMLDocuments.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Tab Attributes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditorKit(new HTMLEditorKit());

    String filename = "yourFile.htm";

    FileReader reader = new FileReader(filename);
    editorPane.read(reader, filename);/*from  w  w w  .j  av a  2s.co m*/

    JScrollPane scrollPane = new JScrollPane(editorPane);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:HyperlinkTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    final JEditorPane ep = new JEditorPane();

    try {/*  ww  w. j a va 2  s .co m*/
        ep.setPage("http://www.java2s.com");
    } catch (IOException e) {
        System.err.println("Bad URL: " + e);
        System.exit(-1);
    }

    HyperlinkListener listener = new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    ep.setPage(e.getURL());
                } catch (IOException ioe) {
                    System.err.println("Error loading: " + ioe);
                }
            }
        }
    };
    ep.addHyperlinkListener(listener);
    ep.setEditable(false);
    JScrollPane pane = new JScrollPane(ep);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(640, 480);
    frame.show();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane jep = new JEditorPane();
    jep.setText("Hello to the public");
    frame.add(jep);/*from   w  w  w.  j  a v a2 s  .  co m*/
    frame.pack();
    frame.setVisible(true);

    highlight(jep, "public");
}