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);
PRINT_PANE.setDocument(getDocument());
/** * Sets the document and the according content type. * * @param type the content type * @param document the document to print */ public void setDocument(String type, Document document) { setContentType(type); m_PrintPane.setDocument(document); }
/** * Sets the document and the according content type. * * @param type the content type * @param document the document to print */ public void setDocument(String type, Document document) { setContentType(type); m_PrintPane.setDocument(document); }
private void setNormalContent(String text) { String qualifyStr = StringUtils.getStrBySpecificLength(text, TEXT_LEN); this.content.setDocument(createNormalDocument(qualifyStr)); }
import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultStyledDocument; public class Tester { public static void main(String[] args) { JTextPane textpane = new JTextPane(); textpane.setDocument(new TabDocument()); JFrame frame = new JFrame(); frame.getContentPane().add(textpane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(200, 200)); frame.setVisible(true); } static class TabDocument extends DefaultStyledDocument { @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { str = str.replaceAll("\t", " "); super.insertString(offs, str, a); } } }
private void setNormalDescription(String text) { String qualifyStr = StringUtils.getStrBySpecificLength(text, TEXT_LEN); this.description.setDocument(createNormalDocument(qualifyStr)); }
private void setNormalText(Text text) { String qualifyStr = StringUtils.getStrBySpecificLength(text.getText(), TEXT_LEN); this.text.setDocument(createNormalDocument(qualifyStr)); }
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); }
public void refreshLog(String s) { if(logText.equals(s)) { return; } logText = s; //txtLog.setText(logText); -- NO. BAD. DON'T DO THIS. Reader stringReader = new StringReader(logText); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument blank = (HTMLDocument) htmlKit.createDefaultDocument(); try { htmlKit.read(stringReader, blank, 0); } catch (Exception e) { // Ignore } txtLog.setDocument(blank); txtLog.setCaretPosition(blank.getLength()); }
@Override public void run() { editor.getDocument().removeUndoableEditListener(undoManager); editor.setDocument(newDocument); newDocument.addUndoableEditListener(undoManager); undoManager.discardAllEdits(); } });
@Override public void run() { editor.getDocument().removeUndoableEditListener(undoManager); editor.setDocument(doc); doc.addUndoableEditListener(undoManager); undoManager.discardAllEdits(); } });
private void applyCalculator(DocumentCalculator calculator) { if (initialCalculator != calculator) return; this.calculator = calculator; textPane.setDocument(calculator.document()); processNewItemsInSwingThread(); threadService.queue(() -> StaticSwingUtils.scrollToBottom(scrollPane)); }
synchronized public void refreshLogs () { // Write messages to new blank document which is not being displayed displayAreaDoc = new DefaultStyledDocument(); // Add all log entries to list and display them Queue<LogRecord> records = new LinkedList<LogRecord>(); for (LogEntry entry : Logger.getLogEntries()) { if (shouldProcess(entry)) { records.add(getLogRecord(entry)); } } displayMessages(records, -1); // Remove newline from start if (displayAreaDoc.getLength() != 0) { try { displayAreaDoc.remove(0, 1); } catch (BadLocationException ignored) { // ignore } } // Swap to displaying new document displayArea.setDocument(displayAreaDoc); }
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) { }
/** * Method for setting a document as the current document for the text pane and re-registering the controls and * settings for it */ public void registerDocument(ExtendedHTMLDocument htmlDoc) { jtpMain.setDocument(htmlDoc); jtpMain.getDocument().addUndoableEditListener(new CustomUndoableEditListener()); jtpMain.getDocument().addDocumentListener(this); jtpMain.setCaretPosition(0); purgeUndos(); registerDocumentStyles(); }
@Override public void pending() { String property = theme.findProperty("pending-background-color"); Color color = Color.decode(property); applyBackground(color); Text content = item.getContent(); java.util.List<Integer> highlightIndexs = content.getHighlightIndexs(); if (CollectionUtils.isNotEmpty(highlightIndexs)) { this.content.setDocument(highlightText(highlightIndexs, content)); } Text description = item.getDescription(); if (description != null) { java.util.List<Integer> descriptionHighlightIndexs = description.getHighlightIndexs(); if (CollectionUtils.isNotEmpty(descriptionHighlightIndexs)) { this.description.setDocument(highlightText(descriptionHighlightIndexs, description)); } } }
@Override public void pending() { applyBackgroundToMiddlePanel(theme.getPendingBackgroundColor()); Text content = item.getText(); java.util.List<Integer> highlightIndexs = content.getHighlightIndexs(); if (CollectionUtils.isNotEmpty(highlightIndexs)) { this.text.setDocument(highlightText(highlightIndexs, content)); } }
public LogViewImpl() { text = new JTextPane(); text.setFont(new Font("monospaced", Font.PLAIN, 12)); editorKit = new LogEditorKit(); text.setEditorKit(editorKit); doc = new LogStyledDocument(); text.setDocument(doc); Style debugStyle = doc.addStyle("debug", null); Style infoStyle = doc.addStyle("info", null); Style warningStyle = doc.addStyle("warning", null); Style errorStyle = doc.addStyle("error", null); commentStyle = doc.addStyle("comment", null); styles[0] = debugStyle; styles[1] = infoStyle; styles[2] = warningStyle; styles[3] = errorStyle; layout = new PatternLayout(); applyPreferences(); }
/** * Creates new form QueryInterfacePanel */ public QueryInterfacePanel(OBDAModel apic, QueryController qc) { this.qc = qc; this.apic = apic; initComponents(); StyleContext style = new StyleContext(); styledDocument = new DefaultStyledDocument(style); queryTextPane.setDocument(styledDocument); queryTextPane.setBackground(Color.WHITE); queryTextPane.setCaretColor(Color.BLACK); queryTextPane.addKeyListener(new CTRLEnterKeyListener()); }