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(String type, String text) 

Source Link

Document

Creates a JEditorPane that has been initialized to the given text.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JEditorPane editor = new JEditorPane("text/html", "<H1>A!</H1><P><FONT COLOR=blue>blue</FONT></P>");
    editor.setEditable(false);//from www  .  j  a va 2s . c o m
    JScrollPane pane = new JScrollPane(editor);
    JFrame f = new JFrame("HTML Demo");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(pane);
    f.setSize(800, 600);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JEditorPane editPane1 = new JEditorPane("text/html", "Try ty\tping some tabs");
    editPane1.setPreferredSize(new Dimension(400, 300));
    JOptionPane.showMessageDialog(null, new JScrollPane(editPane1));
    JOptionPane.showMessageDialog(null, new JScrollPane(new JEditorPane("text/html", editPane1.getText())));
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JEditorPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JEditorPane editor = new JEditorPane("text/html",
            "<H3>Help</H3><center>www.java2s.com</center><li>One<li><i>Two</i><li><u>Three</u>");
    editor.setEditable(false);//from w w w. j ava  2 s  . c  o  m
    JScrollPane scrollPane = new JScrollPane(editor);
    f.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JEditorPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JEditorPane editor = new JEditorPane("text/html",
            "<H3>Help</H3><center><IMG src=file:///c:/a.jpg></center><li>One<li><i>Two</i><li><u>Three</u>");
    editor.setEditable(false);// w  ww.  j av a 2 s  .  co m
    JScrollPane scrollPane = new JScrollPane(editor);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:EditorSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JEditorPane Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = f.getContentPane();
    JEditorPane editor = new JEditorPane("text/html",
            "<H3>Help</H3><center><IMG src=file:///c:/cpress/code/Ch01/logo.jpg></center><li>One<li><i>Two</i><li><u>Three</u>");
    editor.setEditable(false);// ww w. j  a  va 2s  . co  m
    JScrollPane scrollPane = new JScrollPane(editor);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String html = "<h1>Hello, world.</h1>";
    int width = 200, height = 100;

    BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().createCompatibleImage(width, height);

    Graphics graphics = image.createGraphics();

    JEditorPane jep = new JEditorPane("text/html", html);
    jep.setSize(width, height);/*from   w  ww  .  j  a v a 2s .c  o  m*/
    jep.print(graphics);

    ImageIO.write(image, "png", new File("Image.png"));
}

From source file:Main.java

private static void createAndShowGUI() throws IOException {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String imgsrc = Main.class.getClassLoader().getSystemResource("a.jpg").toString();
    frame.getContentPane()/*www .j  a  va  2 s. c  om*/
            .add(new JEditorPane("text/html", "<html><img src='" + imgsrc + "' width=200height=200></img>"));
    frame.pack();

    frame.setVisible(true);
}

From source file:com.mirth.connect.plugins.rtfviewer.RTFViewer.java

@Override
public void viewAttachments(List<String> attachmentIds) {
    // do viewing code

    Frame frame = new Frame("RTF Viewer");

    frame.setLayout(new BorderLayout());

    try {//from  w w  w  .j ava  2 s .c  o m

        Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0));
        byte[] rawRTF = Base64.decodeBase64(attachment.getData());
        JEditorPane jEditorPane = new JEditorPane("text/rtf", new String(rawRTF));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getData()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertException(parent, e.getStackTrace(), e.getMessage());
    }
}

From source file:com.mirth.connect.plugins.textviewer.TextViewer.java

@Override
public void viewAttachments(String channelId, Long messageId, String attachmentId) {
    // do viewing code
    Frame frame = new Frame("Text Viewer");
    frame.setLayout(new BorderLayout());

    try {// w ww  .ja v a 2s.c  o m
        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] content = Base64.decodeBase64(attachment.getContent());

        boolean isRTF = attachment.getType().toLowerCase().contains("rtf");
        //TODO set character encoding
        JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getContent()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:net.sf.jasperreports.engine.util.JEditorPaneRtfMarkupProcessor.java

@Override
public String convert(String srcText) {
    JEditorPane editorPane = new JEditorPane("text/rtf", srcText);
    editorPane.setEditable(false);//from  w  w  w  .j  a v a  2 s .  com

    List<Element> elements = new ArrayList<Element>();

    Document document = editorPane.getDocument();

    Element root = document.getDefaultRootElement();
    if (root != null) {
        addElements(elements, root);
    }

    String chunk = null;
    Element element = null;
    int startOffset = 0;
    int endOffset = 0;

    JRStyledText styledText = new JRStyledText();
    styledText.setGlobalAttributes(new HashMap<Attribute, Object>());
    for (int i = 0; i < elements.size(); i++) {
        if (chunk != null) {
            styledText.append(chunk);
            styledText.addRun(
                    new JRStyledText.Run(getAttributes(element.getAttributes()), startOffset, endOffset));
        }

        chunk = null;
        element = elements.get(i);
        startOffset = element.getStartOffset();
        endOffset = element.getEndOffset();

        try {
            chunk = document.getText(startOffset, endOffset - startOffset);
        } catch (BadLocationException e) {
            if (log.isDebugEnabled()) {
                log.debug("Error converting markup.", e);
            }
        }

    }

    if (chunk != null && !"\n".equals(chunk)) {
        styledText.append(chunk);
        styledText.addRun(new JRStyledText.Run(getAttributes(element.getAttributes()), startOffset, endOffset));
    }

    return JRStyledTextParser.getInstance().write(styledText);
}