本文整理汇总了Java中javax.swing.text.StyleContext.addAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java StyleContext.addAttribute方法的具体用法?Java StyleContext.addAttribute怎么用?Java StyleContext.addAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleContext
的用法示例。
在下文中一共展示了StyleContext.addAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSearchPanel
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private Component createSearchPanel() {
StyleContext styleContent = StyleContext.getDefaultStyleContext();
AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);
AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);
searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
searchPanel.hide();
return searchPanel.getComponent();
}
示例2: appendToPane
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void appendToPane(JTextPane tp, String msg, MessageType t)
{
boolean scrollToBottom = scrollPane.getVerticalScrollBar().getValue() == scrollPane.getVerticalScrollBar().getMaximum();
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = SimpleAttributeSet.EMPTY;
MessageStyle ms = theme.getStyle(t);
aset = sc.addAttribute(aset, StyleConstants.Foreground, ms.getForeground() == null ? tp.getForeground() : ms.getForeground());
aset = sc.addAttribute(aset, StyleConstants.Background, ms.getBackground() == null ? tp.getBackground() : ms.getBackground());
aset = sc.addAttribute(aset, StyleConstants.Bold, ms.isBold());
aset = sc.addAttribute(aset, StyleConstants.Italic, ms.isItalic());
aset = sc.addAttribute(aset, StyleConstants.Underline, ms.isUnderlined());
StyledDocument sd = tp.getStyledDocument();
try
{
sd.insertString(sd.getLength(), msg, aset);
}
catch(BadLocationException e)
{
e.printStackTrace();
}
if(scrollToBottom)
{
scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum());
}
}
示例3: appendToPane
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Appends stylized text to a textpane
*
* @param tp
* Textpane
* @param msg
* Message to append. Will automatically place newline at end.
* @param c
* Color of text.
*/
public static void appendToPane(JTextPane tp, String msg, Color c) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
int len = tp.getDocument().getLength(); // same value as
// getText().length();
tp.setCaretPosition(len); // place caret at the end (with no selection)
StyledDocument doc = tp.getStyledDocument();
try {
doc.insertString(doc.getLength(), msg + "\n", aset);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例4: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
@Override
public void append(String str, Color c) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Sans");
aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
/*
* int len = area.getDocument().getLength(); area.setCaretPosition(len);
* area.setCharacterAttributes(aset, false); area.replaceSelection(str);
*/
DefaultStyledDocument document = (DefaultStyledDocument) area.getDocument();
try {
if (area.getText().length() < 3)
area.setText("");
// document.insertString(0, str, aset);
// else
document.insertString(document.getEndPosition().getOffset() - 1, str, aset);
} catch (BadLocationException e) {}
}
示例5: setupTabStops
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void setupTabStops() {
// Ugly piece of code; needed because default tab indentation is too
// big.
StyleContext sc = StyleContext.getDefaultStyleContext();
Toolkit t = Toolkit.getDefaultToolkit();
FontMetrics fm = t.getFontMetrics(new Font("Courier", Font.PLAIN, 14));
int cw = fm.stringWidth(" ");
final TabStop[] tabStops = new TabStop[60];
for (int i = 0; i < tabStops.length; i++)
tabStops[i] = new TabStop((i + 1) * cw);
TabSet tabs = new TabSet(tabStops);
AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY,
StyleConstants.TabSet, tabs);
pane.setParagraphAttributes(paraSet, false);
}
示例6: appendToLog
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
* Appends a message to the logging area.
*
* @param message
* Message to add
* @param color
* Color of the message
*/
private void appendToLog(final String message, final Color color) {
final StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, DEFAULT_FONT);
aset = sc.addAttribute(aset, StyleConstants.Alignment, Integer.valueOf(StyleConstants.ALIGN_JUSTIFIED));
final int len = this.mLogArea.getDocument().getLength();
this.mLogArea.setCaretPosition(len);
this.mLogArea.setCharacterAttributes(aset, false);
this.mLogArea.setEditable(true);
this.mLogArea.replaceSelection(message);
this.mLogArea.setEditable(false);
}
示例7: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color c, String s) {
if (c == null)
c = defaultColor;
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
try {
getDocument().insertString(getDocument().getLength(), s, as);
} catch (BadLocationException e) {
}
}
示例8: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color c, String s) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
int len = getDocument().getLength();
setCaretPosition(len);
setCharacterAttributes(aset, false);
replaceSelection(s);
}
示例9: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color c, String s) {
if (c == null)
c = defaultColor;
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
try {
getDocument().insertString(getDocument().getLength(), s, as);
} catch (BadLocationException e) {
}
}
示例10: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color color, String s) {
StyleContext styleContext = StyleContext.getDefaultStyleContext();
AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
int len = getDocument().getLength();
setCaretPosition(len);
setCharacterAttributes(attributeSet, false);
replaceSelection(s);
}
示例11: setTabSize
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void setTabSize(int size) {
TabStop[] tabs = new TabStop[1];
tabs[0] = new TabStop(size, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
// tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
// tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
// tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE);
TabSet tabset = new TabSet(tabs);
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
StyleConstants.TabSet, tabset);
textPane.setParagraphAttributes(aset, false);
}
示例12: appendToPane
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void appendToPane(String msg, Color c)
{
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
int len = textPane.getDocument().getLength();
textPane.setCaretPosition(len);
textPane.setCharacterAttributes(aset, false);
textPane.replaceSelection(msg);
}
示例13: append
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void append (String mensaje, Color color) {
StyleContext styleContext = StyleContext.getDefaultStyleContext();
AttributeSet attributeSet = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
attributeSet = styleContext.addAttribute(attributeSet, StyleConstants.FontFamily, "Lucida Console");
attributeSet = styleContext.addAttribute(attributeSet, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
int longitud = historial.getDocument().getLength();
historial.setCaretPosition(longitud);
historial.setCharacterAttributes(attributeSet, false);
historial.replaceSelection(mensaje);
}
示例14: appendError
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void appendError(String s) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground,
Color.RED);
textField.setCharacterAttributes(aset, false);
textField.replaceSelection(s);
int len = doc.getLength();
textField.setCaretPosition(len);
}
示例15: appendText
import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void appendText(String s) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground,
Color.BLACK);
textField.setCharacterAttributes(aset, false);
textField.replaceSelection(s);
int len = doc.getLength();
textField.setCaretPosition(len);
}