本文整理了Java中javax.swing.JTextPane.setDocument()
方法的一些代码示例,展示了JTextPane.setDocument()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.setDocument()
方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:setDocument
暂无
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: groovy/groovy-core
PRINT_PANE.setDocument(getDocument());
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* 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);
}
代码示例来源:origin: Waikato/weka-trunk
/**
* 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);
}
代码示例来源:origin: zgqq/mah
private void setNormalContent(String text) {
String qualifyStr = StringUtils.getStrBySpecificLength(text, TEXT_LEN);
this.content.setDocument(createNormalDocument(qualifyStr));
}
代码示例来源:origin: stackoverflow.com
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);
}
}
}
代码示例来源:origin: zgqq/mah
private void setNormalDescription(String text) {
String qualifyStr = StringUtils.getStrBySpecificLength(text, TEXT_LEN);
this.description.setDocument(createNormalDocument(qualifyStr));
}
代码示例来源:origin: zgqq/mah
private void setNormalText(Text text) {
String qualifyStr = StringUtils.getStrBySpecificLength(text.getText(), TEXT_LEN);
this.text.setDocument(createNormalDocument(qualifyStr));
}
代码示例来源:origin: dboissier/jenkins-control-plugin
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);
}
代码示例来源:origin: MegaMek/mekhq
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());
}
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public void run() {
editor.getDocument().removeUndoableEditListener(undoManager);
editor.setDocument(newDocument);
newDocument.addUndoableEditListener(undoManager);
undoManager.discardAllEdits();
}
});
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public void run() {
editor.getDocument().removeUndoableEditListener(undoManager);
editor.setDocument(doc);
doc.addUndoableEditListener(undoManager);
undoManager.discardAllEdits();
}
});
代码示例来源:origin: org.scijava/scijava-ui-swing
private void applyCalculator(DocumentCalculator calculator) {
if (initialCalculator != calculator) return;
this.calculator = calculator;
textPane.setDocument(calculator.document());
processNewItemsInSwingThread();
threadService.queue(() -> StaticSwingUtils.scrollToBottom(scrollPane));
}
代码示例来源:origin: Slowpoke101/FTBLaunch
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);
}
代码示例来源:origin: stackoverflow.com
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) {
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
/**
* 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();
}
代码示例来源:origin: zgqq/mah
@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));
}
}
}
代码示例来源:origin: zgqq/mah
@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));
}
}
代码示例来源:origin: protegeproject/protege
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();
}
代码示例来源:origin: ontop/ontop
/**
* 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());
}
内容来源于网络,如有侵权,请联系作者删除!