@NotNull public static JTextPane createDescriptionPane() { JTextPane result = new JTextPane(); result.addHyperlinkListener(new BrowserHyperlinkListener()); result.setContentType("text/html"); Font descriptionFont = UIUtil.getLabelFont(UIUtil.FontSize.SMALL); HTMLEditorKit editorKit = UIUtil.getHTMLEditorKit(); editorKit.getStyleSheet().addRule("body, p {" + "color:#" + ColorUtil.toHex(UIUtil.getLabelFontColor(UIUtil.FontColor.BRIGHTER)) + ";" + "font-family:" + descriptionFont.getFamily() + ";" + "font-size:" + descriptionFont.getSize() + "pt;}"); result.setHighlighter(null); result.setEditorKit(editorKit); return result; } }
JTextPane text_panel = new JTextPane(); HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); text_panel.setEditorKit(kit); text_panel.setDocument(doc); kit.insertHTML(doc, doc.getLength(), "<b>hello", 0, 0, HTML.Tag.B); kit.insertHTML(doc, doc.getLength(), "<font color='red'><u>world</u></font>", 0, 0, null);
this.result.setEditorKit(new HTMLEditorKitTextPaneWrap());
getContentPane().setLayout(new BorderLayout()); JTextPane jtp = new JTextPane(); jtp.setEditorKit(new WrapEditorKit()); JScrollPane jsp = new JScrollPane(jtp); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
I18nView.addComponentForKey("NETWORK_TAB_RESPONSE_LABEL", labelConsoleq); PanelConsoles.NETWORK_TAB_PREVIEW.setEditorKit(new HTMLEditorKitTextPaneWrap());
EditorKit editorKit = new SomeBetterEditorKit(); JTextPane textPane = new JTextPane(); textPane.setEditorKit( editorKit );
JTextPane pane = new JTextPane(); pane.setEditorKit(new HTMLEditorKit());
final HTMLEditorKit htmlKit = new HTMLEditorKit(); final JTextPane textPane = new JTextPane( ); textPane.setEditorKit(htmlKit); textPane.setEditable(true); JScrollPane scrollPane = new JScrollPane( textPane ); Document doc = textPane.getDocument(); System.out.println(doc.getClass().getName()); // It's an HTML Document
/** * Create a new PatternHighlightRenderer. * <p> * Disable line wrap when using this as a single-line renderer. This is because this renderer uses a * {@link JTextPane} as its rendering component, and the default JTextPane wrapping results in words simply * disappearing when used as a single-line renderer. * * @param lineWrapEnabled * Whether to allow line wrapping * @see <a href="https://sourceforge.net/p/omegat/bugs/862/">Bug #862</a> */ public PatternHighlightRenderer(boolean lineWrapEnabled) { component = new JTextPane(); if (!lineWrapEnabled) { component.setEditorKit(new NoWrapEditorKit()); } }
EditorKit editorKit = new StyledEditorKit() { public Document createDefaultDocument() { return new ColoredDocument(); } }; JTextPane textPane = new JTextPane(); textPane.setEditorKit( editorKit ); FileReader fr = new FileReader( ... ); BufferedReader br = new BufferedReader( fr ); textPane.read( br, null );
/** * Creates a text pane. * * @param viewDescriptor * the component view descriptor. * @return the created text pane. */ protected JTextPane createJTextPane(IPropertyViewDescriptor viewDescriptor) { JTextPane textPane = new JTextPane(); textPane.setEditorKit(new HTMLEditorKit()); textPane.setDragEnabled(true); return textPane; }
import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.html.HTMLEditorKit; public class StyleTestApp { public static void main(final String[] args) { final JFrame f = new JFrame("test"); //f.getContentPane().add(new JTextArea("<html>HELLO <font size=\"3\" face=\"verdana\" color=\"red\">WORLD</font></html>")); final JTextPane p = new JTextPane(); // the HTMLEditorKit is not enabled by default in the JTextPane class. p.setEditorKit(new HTMLEditorKit()); p.setText("<html>HELLO <font size=\"3\" face=\"verdana\" color=\"red\">WORLD</font></html>"); f.getContentPane().add(p); f.pack(); f.setVisible(true); } }
private void postInitComponents() { final HTMLEditorKit htmlkit = new HTMLEditorKit(); final StyleSheet css = htmlkit.getStyleSheet(); if (css.getStyleSheets() == null) { final StyleSheet css2 = new StyleSheet(); final Font f = new JLabel().getFont(); css2.addRule(new StringBuffer("body { font-size: ").append(f.getSize()) // NOI18N .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N css2.addStyleSheet(css); htmlkit.setStyleSheet(css2); } jTextPane1.setEditorKit(htmlkit); jTextPane1.setText(NbBundle.getMessage(BrokenPlatformCustomizer.class, "MSG_BrokenProject")); // NOI18N }
private void enableHTML() { messageField.setContentType("text/html"); messageField.setOpaque(false); messageField.setEditable(false); messageField.setEditorKit(new VHTMLEditorKit()); }
private JTextPane getTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); StyledEditorKit kit = new StyledEditorKit(); jTextPane.setEditorKit(kit); jTextPane.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n"); jTextPane.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); jTextPane.setText(_archetypeElementVO.getDescription()); jTextPane.setEditable(false); jTextPane.setBackground(null); jTextPane.setPreferredSize(new java.awt.Dimension(250, 70)); } return jTextPane; }
private JTextPane getTextPane() { if (jTextPane == null) { jTextPane = new JTextPane(); StyledEditorKit kit = new StyledEditorKit(); jTextPane.setEditorKit(kit); jTextPane.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n"); jTextPane.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 12)); jTextPane.setText(OpenEHRLanguageManager.getMessage("NullValueDesc")); jTextPane.setEditable(false); jTextPane.setBackground(null); jTextPane.setPreferredSize(new java.awt.Dimension(250, 70)); } return jTextPane; }
private void initDebugTextPane() { HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); HTMLDocument htmlDocument = new HTMLDocument(); debugTextPane.setEditable(false); debugTextPane.setBackground(Color.WHITE); debugTextPane.setEditorKit(htmlEditorKit); htmlEditorKit.install(debugTextPane); debugTextPane.setDocument(htmlDocument); }
JTextPane textPane = new JTextPane(); JButton button = new JButton("Button"); button.setAlignmentY(0.85f); HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); textPane.setEditorKit(kit); textPane.setDocument(doc); try { kit.insertHTML(doc, doc.getLength(), "<p color='#FF0000'>Cool!", 0, 0, HTML.Tag.P); kit.insertHTML(doc, doc.getLength(), "<p></p>", 0, 0, null); } catch (BadLocationException ex) { } catch (IOException ex) { }
private void disableHTML() { messageField.setContentType("text/plain"); final Color color = getStyle(). getBaseValues().getColor(TEXT_COLOR_KEY); messageField.setForeground(color); messageField.setOpaque(false); messageField.setEditable(false); messageField.setEditorKit(new StyledEditorKit()); }
/** Creates new form SelectModePanel */ public SelectModePanel(SelectModeDescriptorPanel controller) { this.controller = controller; initComponents(); instructions.setEditorKit(new HTMLEditorKit()); instructions.setBackground(instructionPanel.getBackground()); disableHostSensitiveComponents(); refreshRunnable = new RefreshRunnable(); refreshSourceFolderTask = RP2.create(refreshRunnable); addListeners(); }