List of usage examples for javax.swing JEditorPane JEditorPane
public JEditorPane()
JEditorPane
. From source file:EditorDropTarget2.java
public static void main(String[] args) { try {/*w ww. ja va2 s . com*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 2"); final JEditorPane pane = new JEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget2 target = new EditorDropTarget2(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); JPanel panel = new JPanel(); final JCheckBox editable = new JCheckBox("Editable"); editable.setSelected(true); panel.add(editable); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editable.isSelected()); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationByPlatform(true);//from ww w .j a v a2 s . c om JEditorPane editPane = new JEditorPane(); JScrollPane scrollPane = new JScrollPane(editPane); editPane.setContentType("text/html"); editPane.setText("<html><p style = \"text-align:center;\">Hello there, How you doing ?<img src = " + "\"http://www.java2s.com/style/download.png" + "\" alt = \"pic\" width = \"15\" height = \"15\" />test test test" + "<br />I hope this is what you wanted!! " + "<img src = \"http://www.java2s.com/style/download.png" + "\" alt = \"pic\" width = \"15\" height = \"15\" /> this is a test.</p></html>\n"); add(scrollPane, BorderLayout.CENTER); setSize(400, 300); setVisible(true); }
From source file:Main.java
public Main() { JEditorPane web = new JEditorPane(); web.setEditable(false);// www . j a v 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 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 w ww . j a v a 2 s . com*/ this.setVisible(true); }
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 av a2 s . c o 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 void createJEditorPane(Container bg, Dimension size) { JEditorPane pane = new JEditorPane(); pane.setEditable(false);//w w w .ja v a2s. c o m HTMLEditorKit editorKit = new HTMLEditorKit(); pane.setEditorKit(editorKit); pane.setSize(size); pane.setMinimumSize(size); pane.setMaximumSize(size); pane.setOpaque(true); pane.setText( "<b><font face=\"Arial\" size=\"50\" align=\"center\" > Unfortunately when I display this string it is too long and doesn't wrap to new line!</font></b>"); bg.add(pane, BorderLayout.CENTER); }
From source file:Main.java
public Main() { JEditorPane editorPane = new JEditorPane(); JScrollPane scrollPane = new JScrollPane(); this.setPreferredSize(new Dimension(300, 300)); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); editorPane.setEditorKit(new PreWrapHTMLEditorKit()); editorPane.setText("" + "<html>" + "<head></head>" + "<body>" + "<pre>long text line long text line long text line long text line (two new lines here!)\n\n" + "long text line long text line long text line long text line long text line long text line</pre>" + "</body>" + "</html>"); scrollPane.setViewportView(editorPane); getContentPane().add(scrollPane);/* w w w . j a va2s . co m*/ pack(); }
From source file:Main.java
public Main() throws Exception { setSize(400, 240);//w ww . j a v a2s .c o m JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); getContentPane().add(topPanel, BorderLayout.CENTER); RTFEditorKit rtf = new RTFEditorKit(); JEditorPane editor = new JEditorPane(); editor.setEditorKit(rtf); JScrollPane scroller = new JScrollPane(); scroller.getViewport().add(editor); topPanel.add(scroller, BorderLayout.CENTER); FileInputStream fi = new FileInputStream("test.rtf"); rtf.read(fi, editor.getDocument(), 0); }
From source file:Main.java
public Main() { setLayout(new BorderLayout()); String text = "<html>one<br>two<br><a name =\"three\"></a>three<br>four<br>five<br>six<br>seven<br>eight<br>nine<br>ten</html>"; StringReader reader = new StringReader(text); html = new JEditorPane(); html.setContentType("text/html"); try {//from www. j av a 2s. c o m html.read(reader, null); } catch (Exception e) { System.out.println(e); } JScrollPane scrollPane = new JScrollPane(html); scrollPane.setPreferredSize(new Dimension(400, 100)); add(scrollPane); html.scrollToReference("three"); }
From source file:EditorDropTarget3.java
public static void main(String[] args) { try {/* w ww. j a v a 2 s .c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("JEditor Pane Drop Target Example 3"); final JEditorPane pane = new JEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget3 target = new EditorDropTarget3(pane); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); JPanel panel = new JPanel(); final JCheckBox editable = new JCheckBox("Editable"); editable.setSelected(true); panel.add(editable); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); }