List of usage examples for javax.swing JEditorPane setEditable
@BeanProperty(description = "specifies if the text can be edited") public void setEditable(boolean b)
TextComponent
should be editable. 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); JScrollPane scrollPane = new JScrollPane(editor); content.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200);//from w ww .ja va 2s .c om f.setVisible(true); }
From source file:ShowHTMLViews.java
public static void main(String[] args) { try {// ww w . jav a 2 s . c om UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } try { JFrame f = new JFrame("HTML Document View Structure"); final JEditorPane ep = new JEditorPane(args[0]); ep.setEditable(false); f.getContentPane().add(new JScrollPane(ep)); f.setSize(400, 300); f.setVisible(true); ep.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { System.out.println("Document:\n"); HTMLDocDisplay.displayModel(ep, System.out); System.out.println("\n\nViews:\n"); HTMLViewDisplayer.displayViews(ep, System.out); } } }); } catch (Exception e) { System.out.println(e); System.exit(1); } }
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 . ja v a 2 s . c om } 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: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 a v a2 s. c om*/ 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:EditorDropTarget2.java
public static void main(String[] args) { try {/* ww w. jav a2 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 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:EditorDropTarget3.java
public static void main(String[] args) { try {/* w w w . j av a2 s.c om*/ 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); }
From source file:EditorDropTarget4.java
public static void main(String[] args) { try {//from ww w. ja 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 4"); // Create an editor with autoscrolling support final JEditorPane pane = new AutoScrollingEditorPane(); // Add a drop target to the JEditorPane EditorDropTarget4 target = new EditorDropTarget4(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); }
From source file:net.sf.texprinter.utils.UIUtils.java
/** * Format an editor to act as a label. I decided to replace all the * occurrences of multiline JLabel's to JEditorPane's instead, so I * want them to look exactly like ordinary JLabels. * //w ww. j a v a 2 s . co m * @param editor The editor to be formatted as a label. */ public static void formatEditorPaneAsLabel(JEditorPane editor) { // disable it editor.setEnabled(false); // make it read only editor.setEditable(false); // transparent editor.setOpaque(false); // set the disabled color as black editor.setDisabledTextColor(Color.BLACK); }
From source file:Main.java
public void createJEditorPane(Container bg, Dimension size) { JEditorPane pane = new JEditorPane(); pane.setEditable(false); HTMLEditorKit editorKit = new HTMLEditorKit(); pane.setEditorKit(editorKit);/*from w w w .j a v a2 s.co m*/ 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 web = new JEditorPane(); web.setEditable(false); try {//from w ww . j av a 2 s . c om 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); }