List of usage examples for javax.swing JEditorPane setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified content, which is expected to be in the format of the content type of this editor. 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);/* www.j ava 2 s . co m*/ frame.setSize(640, 480); frame.setVisible(true); }
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 ww .j av a2 s. c o m*/ frame.pack(); frame.setVisible(true); highlight(jep, "public"); }
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.j a v a2s.com 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:Main.java
public static void main(String[] args) { JFrame fr = new JFrame(); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane pane = new JEditorPane(); pane.setEditorKit(new NewEditorKit()); pane.setText( "test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test "); StyledDocument doc = (StyledDocument) pane.getDocument(); MutableAttributeSet attr = new SimpleAttributeSet(); attr.addAttribute("strike-color", Color.red); doc.setCharacterAttributes(0, 9, attr, false); attr.addAttribute("strike-color", Color.blue); doc.setCharacterAttributes(10, 19, attr, false); JScrollPane sp = new JScrollPane(pane); fr.getContentPane().add(sp);/*from w w w . ja va2s . c om*/ fr.setSize(300, 300); fr.setLocationRelativeTo(null); fr.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JEditorPane jep = new JEditorPane(); jep.setEditable(false);//from w w w.j a va2 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: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 ww. j a v 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 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); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(htmlPane)); frame.pack();//from w w w . j av a 2s. c o m 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 w w. j a v a 2s . 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:Main.java
public static void setPaneHtmlText(String htmlText, JEditorPane pane) { if (htmlText == null) { pane.setText(""); return;//from w w w . j a v a 2 s .c o m } else if (htmlText.length() == 0) { pane.setText(""); return; } StringReader htmReader = new StringReader(htmlText); HTMLEditorKit kit = (HTMLEditorKit) pane.getEditorKitForContentType("text/html"); HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument(); ParserDelegator parser = new ParserDelegator(); try { parser.parse(htmReader, doc.getReader(0), true); } catch (IOException ex) { ex.printStackTrace(); } pane.setDocument(doc); }
From source file:com.rapidminer.gui.flow.processrendering.annotations.AnnotationDrawUtils.java
/** * Calculates the preferred height of an editor pane with the given fixed width for the * specified string./*from w w w. jav a 2 s .c o m*/ * * @param comment * the annotation comment string * @param width * the width of the content * @return the preferred height given the comment */ public static int getContentHeight(final String comment, final int width) { if (comment == null) { throw new IllegalArgumentException("comment must not be null!"); } JEditorPane dummyEditorPane = new JEditorPane("text/html", ""); dummyEditorPane.setText(comment); dummyEditorPane.setBorder(null); dummyEditorPane.setSize(width, Short.MAX_VALUE); // height is not exact. Multiply by magic number to get a more fitting value... if (SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX || SystemInfoUtilities.getOperatingSystem() == OperatingSystem.UNIX || SystemInfoUtilities.getOperatingSystem() == OperatingSystem.SOLARIS) { return (int) (dummyEditorPane.getPreferredSize().getHeight() * 1.05f); } else { return (int) dummyEditorPane.getPreferredSize().getHeight(); } }