本文整理了Java中javax.swing.JTextPane.getStyledDocument()
方法的一些代码示例,展示了JTextPane.getStyledDocument()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.getStyledDocument()
方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:getStyledDocument
暂无
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Highlights specified text region by changing the character attributes
*/
private void highlightText(int start, int end, SimpleAttributeSet style) {
if (start < end) {
textPane.getStyledDocument().setCharacterAttributes(start, end - start + 1, style, false);
}
}
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
textPane.setText( "original text" );
StyledDocument doc = textPane.getStyledDocument();
// Define a keyword attribute
SimpleAttributeSet keyWord = new SimpleAttributeSet();
StyleConstants.setForeground(keyWord, Color.RED);
StyleConstants.setBackground(keyWord, Color.YELLOW);
StyleConstants.setBold(keyWord, true);
// Add some text
try
{
doc.insertString(0, "Start of text\n", null );
doc.insertString(doc.getLength(), "\nEnd of text", keyWord );
}
catch(Exception e) { System.out.println(e); }
代码示例来源:origin: stackoverflow.com
public class Main {
public static void main(String[] args) {
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("I'm a Style", null);
StyleConstants.setForeground(style, Color.red);
try { doc.insertString(doc.getLength(), "BLAH ",style); }
catch (BadLocationException e){}
StyleConstants.setForeground(style, Color.blue);
try { doc.insertString(doc.getLength(), "BLEH",style); }
catch (BadLocationException e){}
JFrame frame = new JFrame("Test");
frame.getContentPane().add(textPane);
frame.pack();
frame.setVisible(true);
}
}
代码示例来源:origin: kiegroup/optaplanner
private JComponent createNoPlannerFoundTextField() {
String infoMessage = "No planner benchmarks have been found in the benchmarkDirectory ("
+ benchmarkAggregator.getBenchmarkDirectory() + ").";
JTextPane textPane = new JTextPane();
textPane.setEditable(false);
textPane.setText(infoMessage);
// center info message
StyledDocument styledDocument = textPane.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
StyleConstants.setBold(center, true);
styledDocument.setParagraphAttributes(0, styledDocument.getLength(),
center, false);
return textPane;
}
代码示例来源:origin: RipMeApp/ripme
/**
* Write a line to the Log section of the GUI
*
* @param text the string to log
* @param color the color of the line
*/
private void appendLog(final String text, final Color color) {
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setForeground(sas, color);
StyledDocument sd = logText.getStyledDocument();
try {
synchronized (this) {
sd.insertString(sd.getLength(), text + "\n", sas);
}
} catch (BadLocationException e) { }
logText.setCaretPosition(sd.getLength());
}
代码示例来源:origin: marytts/marytts
pane.setParagraphAttributes(set, false);
StyledDocument doc = pane.getStyledDocument();
final Style alertStyle = doc.addStyle("Alert", null);
StyleConstants.setForeground(alertStyle, Color.red);
代码示例来源:origin: groovy/groovy-core
protected void addStylesToDocument(JTextPane outputArea) {
StyledDocument doc = outputArea.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "Monospaced");
promptStyle = doc.addStyle("prompt", regular);
StyleConstants.setForeground(promptStyle, Color.BLUE);
commandStyle = doc.addStyle("command", regular);
StyleConstants.setForeground(commandStyle, Color.MAGENTA);
outputStyle = doc.addStyle("output", regular);
StyleConstants.setBold(outputStyle, true);
}
代码示例来源:origin: magefree/mage
private void drawText(java.util.List<String> strings) {
text.setText("");
StyledDocument doc = text.getStyledDocument();
try {
for (String line : strings) {
doc.insertString(doc.getLength(), line + '\n', doc.getStyle("regular"));
}
} catch (BadLocationException ble) {
}
text.setCaretPosition(0);
}
代码示例来源:origin: magefree/mage
protected void drawText() {
text.setText("");
StyledDocument doc = text.getStyledDocument();
try {
for (String rule : getRules()) {
doc.insertString(doc.getLength(), rule + '\n', doc.getStyle("small"));
}
} catch (BadLocationException e) {
}
text.setCaretPosition(0);
}
代码示例来源:origin: stackoverflow.com
jtp = new JTextPane();
jtp.setText("\ntype some text in the above empty line and check the wrapping behavior");
doc = jtp.getStyledDocument();
doc.addDocumentListener(new DocumentListener() {
代码示例来源:origin: apache/pdfbox
public void log(String name, String level, Object o, Throwable throwable)
StyledDocument doc = textPane.getStyledDocument();
代码示例来源:origin: stackoverflow.com
doc = jta.getStyledDocument();
jsp = new JScrollPane(jta);
jsp.setPreferredSize(new Dimension(height, width));
代码示例来源:origin: magefree/mage
/**
* Creates new form Card
*
* @param card
* @param bigCard
* @param dimension
* @param gameId
*/
public Card(CardView card, BigCard bigCard, CardDimensions dimension, UUID gameId) {
this.dimension = dimension;
initComponents();
this.gameId = gameId;
this.card = card;
this.bigCard = bigCard;
small = new BufferedImage(Config.dimensions.frameWidth, Config.dimensions.frameHeight, BufferedImage.TYPE_INT_RGB);
backgroundName = getBackgroundName();
background = ImageHelper.getBackground(card, backgroundName);
StyledDocument doc = text.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "arial");
Style s = doc.addStyle("small", regular);
StyleConstants.setFontSize(s, 9);
//addMouseListener(this);
//text.addMouseListener(this);
//addFocusListener(this);
//addMouseMotionListener(this);
//text.addMouseMotionListener(this);
//addComponentListener(this);
}
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
Style bold = textPane.addStyle("bold", null);
StyleConstants.setBold(bold, true);
textPane.setText("I'll be bold.");
textPane.getStyledDocument().setCharacterAttributes(8, 4, bold, true);
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
SimpleAttributeSet style = new SimpleAttributeSet();
StyleConstants.setLeftIndent(style, 20);
StyleConstants.setFirstLineIndent(style, -20);
StyleConstants.setForeground(style, Color.BLUE);
doc.setParagraphAttributes(0, doc.getLength(), style, true);
代码示例来源:origin: ontop/ontop
private void prepareTextPane() {
resetStyles();
parent.setBorder(null);
parent.getStyledDocument().addDocumentListener(
new DocumentListener() {
@Override public void insertUpdate(DocumentEvent e) { handleDocumentUpdated(); }
@Override public void removeUpdate(DocumentEvent e) { handleDocumentUpdated(); }
@Override public void changedUpdate(DocumentEvent e) { /* NO-OP */ }
}
);
}
代码示例来源:origin: protegeproject/protege
@Override
public void mouseMoved(MouseEvent e) {
int pos = previewText.viewToModel(e.getPoint());
StyledDocument doc = previewText.getStyledDocument();
Element element = doc.getCharacterElement(pos);
AttributeSet addtributes = element.getAttributes();
Style style = doc.getStyle((String) addtributes
.getAttribute(StyleConstants.NameAttribute));
previewText.setToolTipText(
"Click to change the " + style.getName() + " color");
}
});
代码示例来源:origin: protegeproject/protege
private static Style getStyleAtPoint(JTextPane text, Point point) {
int pos = text.viewToModel(point);
StyledDocument doc = text.getStyledDocument();
Element element = doc.getCharacterElement(pos);
AttributeSet addtributes = element.getAttributes();
return doc.getStyle((String) addtributes
.getAttribute(StyleConstants.NameAttribute));
}
代码示例来源:origin: otros-systems/otroslogviewer
private void fillText() throws BadLocationException {
textArea.setText("");
StyledDocument sd = textArea.getStyledDocument();
sd.insertString(0, "OtrosLogViewer\n", titleStyle);
sd.insertString(sd.getLength(), "Build: " + build + "\n", mainStyle);
sd.insertString(sd.getLength(), "Project web page: https://github.com/otros-systems/otroslogviewer/\n", mainStyle);
sd.insertString(sd.getLength(), "Program documentation: https://github.com/otros-systems/otroslogviewer/wiki/Introduction?tm=6 \n", mainStyle);
sd.insertString(sd.getLength(), "License: Apache Commons 2.0", licenceStyle);
}
代码示例来源:origin: org.codehaus.groovy/groovy-console
protected void addStylesToDocument(JTextPane outputArea) {
StyledDocument doc = outputArea.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", def);
StyleConstants.setFontFamily(def, "Monospaced");
promptStyle = doc.addStyle("prompt", regular);
StyleConstants.setForeground(promptStyle, Color.BLUE);
commandStyle = doc.addStyle("command", regular);
StyleConstants.setForeground(commandStyle, Color.MAGENTA);
outputStyle = doc.addStyle("output", regular);
StyleConstants.setBold(outputStyle, true);
}
内容来源于网络,如有侵权,请联系作者删除!