本文整理了Java中javax.swing.JTextPane.addStyle()
方法的一些代码示例,展示了JTextPane.addStyle()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.addStyle()
方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:addStyle
暂无
代码示例来源: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
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();
Style style = textPane.addStyle("Blue", null);
StyleConstants.setForeground(style, Color.blue);
代码示例来源:origin: stackoverflow.com
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("I'm a Style", null);
StyleConstants.setForeground(style, Color.red);
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
JTextPane jtp = new JTextPane();
StyledDocument doc = jtp.getStyledDocument();
Style style = jtp.addStyle("Red coloured text", null);
StyleConstants.setForeground(style, Color.red);
try { doc.insertString(doc.getLength(), "Style text",style); }
catch (BadLocationException e){}
StyleConstants.setForeground(style, Color.blue);
try { doc.insertString(doc.getLength(), "Style text 2",style); }
catch (BadLocationException e){}
JFrame frame = new JFrame("ColourCheck");
frame.getContentPane().add(jtp);
frame.pack();
frame.setVisible(true);
}
代码示例来源:origin: org.scijava/scijava-ui-swing
private Style createStyle(final String name, final Style parent,
final Color foreground, final Boolean bold, final Boolean italic)
{
final Style style = textPane.addStyle(name, parent);
if (foreground != null) StyleConstants.setForeground(style, foreground);
if (bold != null) StyleConstants.setBold(style, bold);
if (italic != null) StyleConstants.setItalic(style, italic);
return style;
}
代码示例来源:origin: zgqq/mah
public Style getHighlightStyle() {
if (matchedTextStyle == null) {
Color highlightForegroundColor = Color.decode(theme.findProperty("text-highlight-foreground-color"));
Color highlightBackgroundColor = Color.decode(theme.findProperty("text-highlight-background-color"));
this.matchedTextStyle = pane.addStyle("highlight", null);
StyleConstants.setForeground(this.matchedTextStyle, highlightForegroundColor);
StyleConstants.setBackground(this.matchedTextStyle, highlightBackgroundColor);
StyleConstants.setFontSize(this.matchedTextStyle, 14);
}
return matchedTextStyle;
}
代码示例来源:origin: zgqq/mah
public Style getNormalTextStyle() {
if (normalTextStyle == null) {
Color foregroundColor = Color.decode(theme.findProperty("text-foreground-color"));
Color backgroundColor = Color.decode(theme.findProperty("text-background-color"));
this.normalTextStyle = pane.addStyle("normalText", null);
StyleConstants.setForeground(this.normalTextStyle, foregroundColor);
StyleConstants.setBackground(this.normalTextStyle, backgroundColor);
StyleConstants.setFontSize(this.normalTextStyle, 14);
return this.normalTextStyle;
}
return normalTextStyle;
}
代码示例来源:origin: org.apache.uima/uimaj-tools
@Override
public void actionPerformed(ActionEvent event) {
Style style = AnnotationDisplayCustomizationFrame.this.styleMap
.get(AnnotationDisplayCustomizationFrame.this.currentTypeName);
if (style == null) {
style = AnnotationDisplayCustomizationFrame.this.textPane.addStyle(
AnnotationDisplayCustomizationFrame.this.currentTypeName,
AnnotationDisplayCustomizationFrame.this.styleMap.get(CAS.TYPE_NAME_ANNOTATION));
}
StyleConstants.setForeground(style, StyleConstants
.getForeground(AnnotationDisplayCustomizationFrame.this.currentStyle));
StyleConstants.setBackground(style, StyleConstants
.getBackground(AnnotationDisplayCustomizationFrame.this.currentStyle));
AnnotationDisplayCustomizationFrame.this.styleMap.put(
AnnotationDisplayCustomizationFrame.this.currentTypeName, style);
enableButtons(false);
AnnotationDisplayCustomizationFrame.this.repaint();
}
代码示例来源:origin: stackoverflow.com
import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
public class BoldSelected {
public static void main(final String[] args) {
new BoldSelected().launchGui();
}
private void launchGui() {
final String title = "Set bold font style for selected text in JTextArea instance";
final JFrame frame = new JFrame("Stack Overflow: " + title);
frame.setBounds(100, 100, 800, 600);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final JTextPane textPane = new JTextPane();
textPane.setText(title + ".");
final Style style = textPane.addStyle("Bold", null);
StyleConstants.setBold(style, true);
textPane.getStyledDocument().setCharacterAttributes(4, 33, style, false);
frame.getContentPane().add(textPane);
frame.setVisible(true);
}
}
代码示例来源:origin: stackoverflow.com
StyledDocument doc = pane.getStyledDocument();
Style style = pane.addStyle("Color Style", null);
StyleConstants.setForeground(style, color);
try {
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("Red Style", null);
StyleConstants.setForeground(style, Color.red);
try {
doc.insertString(doc.getLength(), "This ", null);
doc.insertString(doc.getLength(), "Apple", style);
doc.insertString(doc.getLength(), " is a good ", null);
doc.insertString(doc.getLength(), "Apple", style);
} catch (BadLocationException e) {
}
JFrame frame = new JFrame("Test");
frame.getContentPane().add(textPane);
frame.pack();
frame.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
JTextPane textpane = new JTextPane(doc);
textpane.setText("Test");
javax.swing.text.Style style = textpane.addStyle("Red", null);
StyleConstants.setForeground(style, Color.RED);
doc.setCharacterAttributes(0, 1, textpane.getStyle("Red"), true);
代码示例来源:origin: org.apache.uima/uimaj-tools
/**
* Sets the current style.
*
* @param style the new current style
*/
private void setCurrentStyle(Style style) {
// Copy style.
this.currentStyle = this.textPane.addStyle(currentStyleName, style);
StyleConstants.setForeground(this.currentStyle, StyleConstants.getForeground(style));
StyleConstants.setBackground(this.currentStyle, StyleConstants.getBackground(style));
}
代码示例来源:origin: org.apache.uima/uimaj-tools
Document doc = this.textPane.getDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style level0 = this.textPane.addStyle("level0", def);
Style level1 = this.textPane.addStyle("level1", level0);
StyleConstants.setBackground(level1, Color.green);
Style level2 = this.textPane.addStyle("level2", level0);
StyleConstants.setBackground(level2, Color.yellow);
Style level3 = this.textPane.addStyle("level3", level0);
StyleConstants.setBackground(level3, Color.orange);
Style[] styleArray = { level0, level1, level2, level3 };
代码示例来源:origin: stackoverflow.com
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("I'm a Style", null);
StyleConstants.setForeground(style, Color.red);
代码示例来源:origin: org.apache.uima/uimaj-tools
this.textPane.addStyle(defaultStyleName, defaultStyle);
setCurrentStyle(style);
this.fgColor = StyleConstants.getForeground(this.currentStyle);
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("Style", null);
StyleConstants.setForeground(style, Color.red);
String word = "Hello";
if (word.equals("Hello")) {
try {
doc.insertString(doc.getLength(), word, style);
} catch (BadLocationException ex) {
ex.printStackTrace();
}
} else {
StyleConstants.setForeground(style, Color.blue);
try {
doc.insertString(doc.getLength(), word, style);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("I'm a Style", null);
StyleConstants.setForeground(style, Color.red);
String word = "Hello";
if (word.equals("Hello") {
try {
doc.insertString(doc.getLength(), word, style);
} catch (BadLocationException ex) {
ex.printStackTrace();
}
} else {
StyleConstants.setForeground(style, Color.blue);
try {
doc.insertString(doc.getLength(), word, style);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: zgqq/mah
private void initStyle(SwingLayoutTheme theme) {
Color highlightForegroundColor = Color.decode(theme.findProperty("text-highlight-foreground-color"));
Color highlightBackgroundColor = Color.decode(theme.findProperty("text-highlight-background-color"));
matchedTextStyle = description.addStyle("matchedText", null);
StyleConstants.setForeground(matchedTextStyle, highlightForegroundColor);
StyleConstants.setBackground(matchedTextStyle, highlightBackgroundColor);
StyleConstants.setFontFamily(matchedTextStyle, FontManager.getInstance().getCurrentFontName());
StyleConstants.setFontSize(matchedTextStyle, 14);
Color foregroundColor = Color.decode(theme.findProperty("text-foreground-color"));
Color backgroundColor = Color.decode(theme.findProperty("text-background-color"));
normalTextStyle = description.addStyle("normalText", null);
StyleConstants.setForeground(normalTextStyle, foregroundColor);
StyleConstants.setBackground(normalTextStyle, backgroundColor);
StyleConstants.setFontFamily(normalTextStyle, FontManager.getInstance().getCurrentFontName());
StyleConstants.setFontSize(normalTextStyle, 14);
}
内容来源于网络,如有侵权,请联系作者删除!