本文整理匯總了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();
}