Example usage for javax.swing JEditorPane setPage

List of usage examples for javax.swing JEditorPane setPage

Introduction

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

Prototype

public void setPage(String url) throws IOException 

Source Link

Document

Sets the current URL being displayed.

Usage

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  a 2s  .  co  m*/
    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 {/*from w  w w .j  ava 2 s  . c  o  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) {

    JEditorPane jep = new JEditorPane();
    jep.setEditable(false);/*  w w w.j  a v  a2  s .  com*/

    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 Main() {

    JEditorPane web = new JEditorPane();
    web.setEditable(false);/* w  w  w  .jav  a  2 s .co  m*/

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

    final JScrollPane scrollPane = new JScrollPane(web);
    getContentPane().add(scrollPane);
    this.setBounds(0, 0, 200, 200);

}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent evt) {
    if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        JEditorPane pane = (JEditorPane) evt.getSource();
        try {//from  w w  w  . j  a  v  a 2  s.c  om
            // Show the new page in the editor pane.
            pane.setPage(evt.getURL());
        } catch (IOException e) {
        }
    }
}

From source file:com.eviware.soapui.support.SoapUIVersionUpdate.java

protected JEditorPane createReleaseNotesPane() {
    JEditorPane text = new JEditorPane();
    try {/* ww  w.j av a 2  s.  c o  m*/
        text.setPage(getReleaseNotes());
        text.setEditable(false);
        text.setBorder(BorderFactory.createLineBorder(Color.black));
    } catch (IOException e) {
        text.setText(NO_RELEASE_NOTES_INFO);
        SoapUI.logError(e);
    }
    return text;
}

From source file:TextSamplerDemo.java

private JEditorPane createEditorPane() {
    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);/*from   w  w w  .j  a v a  2s.co m*/
    java.net.URL helpURL = TextSamplerDemo.class.getResource("TextSamplerDemoHelp.html");
    if (helpURL != null) {
        try {
            editorPane.setPage(helpURL);
        } catch (IOException e) {
            System.err.println("Attempted to read a bad URL: " + helpURL);
        }
    } else {
        System.err.println("Couldn't find file: TextSampleDemoHelp.html");
    }

    return editorPane;
}

From source file:net.sf.housekeeper.swing.MainFrame.java

/**
 * Shows the About dialog for the application.
 *//*w w w  . ja  v a2  s .  co m*/
private void showAboutDialog() {
    final JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);
    final String aboutFile = "/net/sf/housekeeper/about.html";
    final URL helpURL = MainFrame.class.getResource(aboutFile);
    if (helpURL != null) {
        try {
            editorPane.setPage(helpURL);
        } catch (IOException ex) {
            LogFactory.getLog(MainFrame.AboutDialogAction.class)
                    .error("Attempted to read a bad URL: " + helpURL, ex);
        }
    } else {
        LogFactory.getLog(MainFrame.AboutDialogAction.class).error("Could not find file: " + aboutFile);
    }

    editorPane.setPreferredSize(new Dimension(400, 200));
    JOptionPane.showMessageDialog(view, editorPane);
}

From source file:EditorPaneTest.java

public EditorPaneFrame() {
    setTitle("EditorPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final Stack<String> urlStack = new Stack<String>();
    final JEditorPane editorPane = new JEditorPane();
    final JTextField url = new JTextField(30);

    // set up hyperlink listener

    editorPane.setEditable(false);// w w w .  j av  a 2 s  . c  om
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    // remember URL for back button
                    urlStack.push(event.getURL().toString());
                    // show URL in text field
                    url.setText(event.getURL().toString());
                    editorPane.setPage(event.getURL());
                } catch (IOException e) {
                    editorPane.setText("Exception: " + e);
                }
            }
        }
    });

    // set up checkbox for toggling edit mode

    final JCheckBox editable = new JCheckBox();
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            editorPane.setEditable(editable.isSelected());
        }
    });

    // set up load button for loading URL

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    };

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(listener);
    url.addActionListener(listener);

    // set up back button and button action

    JButton backButton = new JButton("Back");
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (urlStack.size() <= 1)
                return;
            try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    });

    add(new JScrollPane(editorPane), BorderLayout.CENTER);

    // put all control components in a panel

    JPanel panel = new JPanel();
    panel.add(new JLabel("URL"));
    panel.add(url);
    panel.add(loadButton);
    panel.add(backButton);
    panel.add(new JLabel("Editable"));
    panel.add(editable);

    add(panel, BorderLayout.SOUTH);
}

From source file:org.jfree.chart.demo.SuperDemo.java

private JPanel createSourceCodePanel() {
    JPanel jpanel = new JPanel(new BorderLayout());
    jpanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    JEditorPane jeditorpane = new JEditorPane();
    jeditorpane.setEditable(false);//from   w w w .  j a v  a 2s  .co m
    java.net.URL url = (SuperDemo.class).getResource("source.html");
    if (url != null)
        try {
            jeditorpane.setPage(url);
        } catch (IOException ioexception) {
            System.err.println("Attempted to read a bad URL: " + url);
        }
    else
        System.err.println("Couldn't find file: source.html");
    JScrollPane jscrollpane = new JScrollPane(jeditorpane);
    jscrollpane.setVerticalScrollBarPolicy(20);
    jscrollpane.setPreferredSize(new Dimension(250, 145));
    jscrollpane.setMinimumSize(new Dimension(10, 10));
    jpanel.add(jscrollpane);
    return jpanel;
}