List of usage examples for javax.swing JEditorPane setContentType
@BeanProperty(bound = false, description = "the type of content") public final void setContentType(String type)
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 av a2s. c om*/ 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: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 ww. j a v a 2s . com } 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:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {" + " background-image: http://www.java2s.com/style/download.png;" + " background-repeat:no-repeat;" + " background-position:left top;" + " background-attachment: scroll;" + " color: #BBBBBB;" + "}" + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>"; String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus."; gui.setPreferredSize(new Dimension(400, 100)); StringBuilder sb = new StringBuilder(); sb.append(HTML);// w w w . jav a 2 s .co m for (int ii = 0; ii < 10; ii++) { sb.append("<h2>Header 2</h2>"); sb.append(PARAGRAPH); } JEditorPane jep = new JEditorPane(); jep.setOpaque(false); jep.setContentType("text/html"); jep.setText(sb.toString()); JScrollPane jsp = new JScrollPane(jep) { BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB); @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(bg, 0, 0, this); } }; jsp.getViewport().setOpaque(false); gui.add(jsp); Main bih = new Main(); JFrame f = new JFrame(); f.add(gui); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:FileTableHTML.java
public static void main(String[] args) throws IOException { // Get the name of the directory to display String dirname = (args.length > 0) ? args[0] : System.getProperty("user.home"); // Create something to display it in. final JEditorPane editor = new JEditorPane(); editor.setEditable(false); // we're browsing not editing editor.setContentType("text/html"); // must specify HTML text editor.setText(makeHTMLTable(dirname)); // specify the text to display // Set up the JEditorPane to handle clicks on hyperlinks editor.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { // Handle clicks; ignore mouseovers and other link-related events if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { // Get the HREF of the link and display it. editor.setText(makeHTMLTable(e.getDescription())); }/*from w w w .j av a2 s . c o m*/ } }); // Put the JEditorPane in a scrolling window and display it. JFrame frame = new JFrame("FileTableHTML"); frame.getContentPane().add(new JScrollPane(editor)); frame.setSize(650, 500); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JEditorPane jep = new JEditorPane(); jep.setEditable(false);//from w w w . ja va 2s. c om 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[] 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);/* ww w .ja va2 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:CheckThreadViolationRepaintManager.java
static void imageUpdateTest() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane editor = new JEditorPane(); frame.setContentPane(editor);//from www.ja v a2s . c om editor.setContentType("text/html"); // it works with no valid image as well editor.setText("<html><img src=\"file:\\lala.png\"></html>"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:com.net2plan.utils.HTMLUtils.java
/** * <p>Saves an HTML content to a given file. Plain text is automatically * wrapped into HTML.</p>/*from w w w. java2s . c o m*/ * * @param file A valid file * @param html HTML content */ public static void saveToFile(File file, String html) { CustomHTMLEditorKit kit = new CustomHTMLEditorKit(); JEditorPane editor = new CustomHTMLEditorKit.CustomJEditorPane(); editor.setEditorKit(kit); editor.setContentType("text/html"); editor.setText(html); editor.setText(CustomHTMLEditorKit.includeNet2PlanHeader(editor.getText())); CustomHTMLEditorKit.saveToFile(file, editor.getText(), kit.getImages()); }
From source file:Main.java
public JComponent makeEditorPane(String bullet) { JEditorPane pane = new JEditorPane(); pane.setContentType("text/html"); pane.setEditable(false);//from w w w .j a va 2s.co m if (bullet != null) { HTMLEditorKit htmlEditorKit = (HTMLEditorKit) pane.getEditorKit(); StyleSheet styleSheet = htmlEditorKit.getStyleSheet(); String u = "http://i.stack.imgur.com/jV29K.png"; styleSheet.addRule(String.format("ul{list-style-image:url(%s);margin:0px 20px;", u)); // styleSheet.addRule("ul{list-style-type:disc;margin:0px 20px;}"); } pane.setText("<html><h1>Heading</h1>Text<ul><li>Bullet point</li></ul></html>"); return pane; }
From source file:Main.java
public Main() { JEditorPane editorPane = new JEditorPane(); editorPane.setContentType("text/HTML"); editorPane.setEditorKit(new HTMLEditorKit()); editorPane.setText("<hr>Welcome to <b>java2s.com!</b><hr>"); JToolBar bar = new JToolBar(); bar.add(new StyledEditorKit.ForegroundAction("Red", Color.red)); bar.add(new StyledEditorKit.ForegroundAction("Blue", Color.blue)); bar.add(new StyledEditorKit.FontSizeAction("12", 12)); bar.add(new StyledEditorKit.FontSizeAction("14", 14)); bar.add(new StyledEditorKit.FontSizeAction("16", 16)); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.add(bar, BorderLayout.NORTH); this.add(editorPane, BorderLayout.CENTER); this.pack();//from www . jav a 2 s .c om this.setVisible(true); }