本文整理了Java中javax.swing.text.StyledDocument.getLength()
方法的一些代码示例,展示了StyledDocument.getLength()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StyledDocument.getLength()
方法的具体详情如下:
包路径:javax.swing.text.StyledDocument
类名称:StyledDocument
方法名:getLength
暂无
代码示例来源: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: stackoverflow.com
StyledDocument doc = textPane.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, 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: 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: groovy/groovy-core
public void actionPerformed(ActionEvent ae) {
JTextComponent tComp = (JTextComponent) ae.getSource();
if (tComp.getDocument() instanceof StyledDocument) {
doc = (StyledDocument) tComp.getDocument();
try {
doc.getText(0, doc.getLength(), segment);
}
catch (Exception e) {
// should NEVER reach here
e.printStackTrace();
}
int offset = tComp.getCaretPosition();
int index = findTabLocation(offset);
buffer.delete(0, buffer.length());
buffer.append('\n');
if (index > -1) {
for (int i = 0; i < index + 4; i++) {
buffer.append(' ');
}
}
try {
doc.insertString(offset, buffer.toString(),
doc.getDefaultRootElement().getAttributes());
}
catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
代码示例来源: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: apache/pdfbox
void writeIndent(StyledDocument docu) throws BadLocationException
{
if (needIndent)
{
for (int i = 0; i < indent; i++)
{
docu.insertString(docu.getLength(), " ", null);
}
needIndent = false;
}
}
}
代码示例来源:origin: ron190/jsql-injection
/**
* Add a colored string to the textpane, measure prompt at the same time.
* @param string Text to append
* @param color Color of text
* @param isAddingPrompt Should we measure prompt length?
*/
private void appendPrompt(String string, Color color, boolean isAddingPrompt) {
try {
StyleConstants.setForeground(this.style, color);
this.styledDocument.insertString(this.styledDocument.getLength(), string, this.style);
if (isAddingPrompt) {
this.prompt += string;
}
} catch (BadLocationException e) {
LOGGER.error(e.getMessage(), e);
}
}
代码示例来源: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: stackoverflow.com
StyleConstants.setFontSize(normal, 72);
StyleConstants.setForeground(normal, Color.blue);
doc.insertString(doc.getLength(), "Test", normal);
jtp.setSelectionStart(doc.getLength());
jtp.insertIcon(UIManager.getIcon("OptionPane.warningIcon"));
jtp.setSelectionStart(doc.getLength());
jtp.insertComponent(new JLabel("Label"));
jtp.setSelectionStart(doc.getLength());
代码示例来源: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: apache/pdfbox
docu.insertString(docu.getLength(), str + " ", NAME_STYLE);
docu.insertString(docu.getLength(), str + " ", null);
docu.insertString(docu.getLength(), "[ ", null);
for (COSBase elem : (COSArray) obj)
docu.insertString(docu.getLength(), "] ", null);
docu.insertString(docu.getLength(), "(", null);
byte[] bytes = ((COSString) obj).getBytes();
for (byte b : bytes)
docu.insertString(docu.getLength(), str, ESCAPE_STYLE);
docu.insertString(docu.getLength(), str, ESCAPE_STYLE);
docu.insertString(docu.getLength(), str, STRING_STYLE);
docu.insertString(docu.getLength(), ") ", null);
docu.insertString(docu.getLength(), str + " ", NUMBER_STYLE);
docu.insertString(docu.getLength(), "<< ", null);
COSDictionary dict = (COSDictionary) obj;
for (Map.Entry<COSName, COSBase> entry : dict.entrySet())
docu.insertString(docu.getLength(), ">> ", null);
代码示例来源:origin: apache/pdfbox
docu.insertString(docu.getLength(), INLINE_IMAGE_BEGIN + "\n", OPERATOR_STYLE);
COSDictionary dic = op.getImageParameters();
for (COSName key : dic.keySet())
docu.insertString(docu.getLength(), "/" + key.getName() + " ", null);
writeToken(value, docu);
docu.insertString(docu.getLength(), "\n", null);
docu.insertString(docu.getLength(), IMAGE_DATA + "\n", INLINE_IMAGE_STYLE);
docu.insertString(docu.getLength(), imageString, null);
docu.insertString(docu.getLength(), "\n", null);
docu.insertString(docu.getLength(), INLINE_IMAGE_END + "\n", OPERATOR_STYLE);
docu.insertString(docu.getLength(), operator + "\n", OPERATOR_STYLE);
代码示例来源:origin: apache/pdfbox
doc.insertString(doc.getLength(), " " + levelText + " ", levelStyle);
doc.insertString(doc.getLength(), " [" + shortName + "]", nameStyle);
doc.insertString(doc.getLength(), " " + message + "\n", null);
textPane.setCaretPosition(doc.getLength());
代码示例来源:origin: mucommander/mucommander
/**
* Inserts a line break in the specified document.
* @param doc document in which to insert the text.
* @throws BadLocationException thrown if something wrong happened to the document.
*/
private static void insertLineBreak(StyledDocument doc) throws BadLocationException {
doc.insertString(doc.getLength(), LINE_BREAK, doc.getStyle(STYLE_NORMAL));
}
代码示例来源:origin: mucommander/mucommander
/**
* Inserts the specified string in the specified document.
* @param doc document in which to insert the text.
* @param string text to insert.
* @throws BadLocationException thrown if something wrong happened to the document.
*/
private static void insertNormalString(StyledDocument doc, String string) throws BadLocationException {
doc.insertString(doc.getLength(), string + LINE_BREAK, doc.getStyle(STYLE_NORMAL));
}
代码示例来源:origin: mucommander/mucommander
/**
* Inserts the specified URL in the specified document.
* @param doc document in which to insert the text.
* @param url url to insert.
* @throws BadLocationException thrown if something wrong happened to the document.
*/
private static void insertUrl(StyledDocument doc, String url) throws BadLocationException {
doc.insertString(doc.getLength(), " ", doc.getStyle(STYLE_NORMAL));
doc.insertString(doc.getLength(), url + LINE_BREAK, doc.getStyle(STYLE_URL));
}
代码示例来源:origin: mucommander/mucommander
/**
* Inserts the specified string and details in the specified document.
* @param doc document in which to insert the text.
* @param string text to insert.
* @param details details that will be added to the text.
* @throws BadLocationException thrown if something wrong happened to the document.
*/
private static void insertDetailedString(StyledDocument doc, String string, String details) throws BadLocationException {
doc.insertString(doc.getLength(), string + " ", doc.getStyle(STYLE_NORMAL));
doc.insertString(doc.getLength(), "(" + details + ")" + LINE_BREAK, doc.getStyle(STYLE_DETAILS));
}
代码示例来源:origin: protegeproject/protege
private void resetStyles(StyledDocument doc) {
doc.setParagraphAttributes(0, doc.getLength(), plainStyle, true);
StyleConstants.setFontSize(fontSizeStyle, getFontSize());
Font f = OWLRendererPreferences.getInstance().getFont();
StyleConstants.setFontFamily(fontSizeStyle, f.getFamily());
doc.setParagraphAttributes(0, doc.getLength(), fontSizeStyle, false);
setupFont();
}
代码示例来源:origin: org.netbeans.api/org-openide-text
public void run() {
try {
addRemoveDocListener(getDoc(), false);
getDoc().remove(0, getDoc().getLength());
addRemoveDocListener(getDoc(), true);
} catch (BadLocationException ble) {
ERR.log(Level.INFO, null, ble);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!