本文整理汇总了Java中javax.swing.text.StyleConstants.setComponent方法的典型用法代码示例。如果您正苦于以下问题:Java StyleConstants.setComponent方法的具体用法?Java StyleConstants.setComponent怎么用?Java StyleConstants.setComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleConstants
的用法示例。
在下文中一共展示了StyleConstants.setComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logDivider
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/** Write a horizontal separator into the log window. */
public void logDivider() {
if (log == null)
return;
clearError();
StyledDocument doc = log.getStyledDocument();
Style dividerStyle = doc.addStyle("bar", styleRegular);
JPanel jpanel = new JPanel();
jpanel.setBackground(Color.LIGHT_GRAY);
jpanel.setPreferredSize(new Dimension(300, 1)); // 300 is arbitrary,
// since it will
// auto-stretch
StyleConstants.setComponent(dividerStyle, jpanel);
reallyLog(".", dividerStyle); // Any character would do; "." will be
// replaced by the JPanel
reallyLog("\n\n", styleRegular);
log.setCaretPosition(doc.getLength());
lastSize = doc.getLength();
}
示例2: appendRequiredAbility
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public void appendRequiredAbility(StyledDocument doc, String key, boolean value) {
final Specification spec = getSpecification();
try {
doc.insertString(doc.getLength(), Messages.getName(key),
doc.getStyle("regular"));
List<JButton> requiredTypes
= transform(spec.getTypesProviding(key, value), alwaysTrue(),
t -> {
JButton typeButton = getButton(t);
typeButton.addActionListener(this);
return typeButton;
});
JButton rt = first(requiredTypes);
if (rt != null) {
doc.insertString(doc.getLength(), " (",
doc.getStyle("regular"));
StyleConstants.setComponent(doc.getStyle("button"), rt);
doc.insertString(doc.getLength(), " ", doc.getStyle("button"));
for (int index = 1; index < requiredTypes.size(); index++) {
JButton button = requiredTypes.get(index);
doc.insertString(doc.getLength(), " / ",
doc.getStyle("regular"));
StyleConstants.setComponent(doc.getStyle("button"), button);
doc.insertString(doc.getLength(), " ",
doc.getStyle("button"));
}
doc.insertString(doc.getLength(), ")",
doc.getStyle("regular"));
}
doc.insertString(doc.getLength(), "\n", doc.getStyle("regular"));
} catch (BadLocationException ble) {
logger.log(Level.WARNING, "Insert fail", ble);
}
}
示例3: insertColonyButtons
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
private void insertColonyButtons(StyledDocument doc, List<Colony> colonies) throws Exception {
for (Colony colony : colonies) {
StyleConstants.setComponent(doc.getStyle("button"), createColonyButton(colony, false));
doc.insertString(doc.getLength(), " ", doc.getStyle("button"));
doc.insertString(doc.getLength(), ", ", doc.getStyle("regular"));
}
doc.remove(doc.getLength() - 2, 2);
}
示例4: insertMessage
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
private void insertMessage(StyledDocument document, ModelMessage message,
Player player) throws BadLocationException {
for (Object o : message.splitLinks(player)) {
if (o instanceof String) {
document.insertString(document.getLength(), (String)o,
document.getStyle("regular"));
} else if (o instanceof JButton) {
JButton b = (JButton)o;
b.addActionListener(this);
StyleConstants.setComponent(document.getStyle("button"), b);
document.insertString(document.getLength(), " ",
document.getStyle("button"));
}
}
}
示例5: logDivider
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/** Write a horizontal separator into the log window. */
public void logDivider() {
if (log==null) return;
clearError();
StyledDocument doc = log.getStyledDocument();
Style dividerStyle = doc.addStyle("bar", styleRegular);
JPanel jpanel = new JPanel();
jpanel.setBackground(Color.LIGHT_GRAY);
jpanel.setPreferredSize(new Dimension(300,1)); // 300 is arbitrary, since it will auto-stretch
StyleConstants.setComponent(dividerStyle, jpanel);
reallyLog(".", dividerStyle); // Any character would do; "." will be replaced by the JPanel
reallyLog("\n\n", styleRegular);
log.setCaretPosition(doc.getLength());
lastSize = doc.getLength();
}