本文整理汇总了Java中javax.swing.text.html.HTMLEditorKit.getStyleSheet方法的典型用法代码示例。如果您正苦于以下问题:Java HTMLEditorKit.getStyleSheet方法的具体用法?Java HTMLEditorKit.getStyleSheet怎么用?Java HTMLEditorKit.getStyleSheet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.html.HTMLEditorKit
的用法示例。
在下文中一共展示了HTMLEditorKit.getStyleSheet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postInitComponents
import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
private void postInitComponents () {
this.jLabel2.setVisible(false);
this.platformHome.setVisible(false);
final Collection installFolders = platform.getInstallFolderURLs();
if (platform.getInstallFolders().isEmpty() && installFolders.size() > 0) {
this.jLabel2.setVisible(true);
this.platformHome.setVisible(true);
this.platformHome.setForeground(new Color (164,0,0));
this.platformHome.setText (Utilities.toFile(URI.create(((URL)installFolders.iterator().next()).toExternalForm())).getAbsolutePath());
}
HTMLEditorKit htmlkit = new HTMLEditorKit();
StyleSheet css = htmlkit.getStyleSheet();
if (css.getStyleSheets() == null) {
StyleSheet css2 = new StyleSheet();
Font f = jLabel2.getFont();
css2.addRule(new StringBuffer("body { font-size: ").append(f.getSize()) // NOI18N
.append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
css2.addStyleSheet(css);
htmlkit.setStyleSheet(css2);
}
jTextPane1.setEditorKit(htmlkit);
jTextPane1.setText(NbBundle.getMessage(BrokenPlatformCustomizer.class,"MSG_BrokenProject"));
}
示例2: PanelBodyContainer
import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
/** Creates new form InstallPanelContainer */
public PanelBodyContainer (String heading, String msg, JPanel bodyPanel) {
head = heading;
message = msg;
this.bodyPanel = bodyPanel;
initComponents ();
HTMLEditorKit htmlkit = new HTMLEditorKitEx();
// override the Swing default CSS to make the HTMLEditorKit use the
// same font as the rest of the UI.
// XXX the style sheet is shared by all HTMLEditorKits. We must
// detect if it has been tweaked by ourselves or someone else
// (code completion javadoc popup for example) and avoid doing the
// same thing again
StyleSheet css = htmlkit.getStyleSheet();
if (css.getStyleSheets() == null) {
StyleSheet css2 = new StyleSheet();
Font f = new JList().getFont();
int size = f.getSize();
css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
.append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
css2.addStyleSheet(css);
htmlkit.setStyleSheet(css2);
}
tpPanelHeader.setEditorKit(htmlkit);
tpPanelHeader.putClientProperty( JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE );
writeToHeader (head, message);
initBodyPanel ();
}
示例3: initHistoryWidget
import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
protected void initHistoryWidget() {
HTMLEditorKit kit = new HTMLEditorKit() {
@Override
public ViewFactory getViewFactory() {
return new WrapHTMLFactory();
}
};
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {text-align: left;}");
styleSheet.addRule("div.my {font-size: 1.2rem; font-style: italic;}");
styleSheet.addRule("div.error {color: red;}");
styleSheet.addRule("img {max-width: 100%;}");
try {
styleSheet.importStyleSheet(
new URL("http://dl.ieclipse.cn/r/smartim.css"));
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
String initText = String.format(
"<html><head></head><body>%s</body></html>", "欢迎使用SmartIM");
historyWidget.setEditorKit(kit);
historyWidget.setDocument(doc);
// historyWidget.setText(initText);
historyWidget.setEditable(false);
historyWidget.setBackground(null);
historyWidget.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
String desc = e.getDescription();
if (!StringUtils.isEmpty(desc)) {
hyperlinkActivated(desc);
}
}
}
});
}
示例4: DetailsPanel
import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
public DetailsPanel() {
initComponents2();
HTMLEditorKit htmlkit = new HTMLEditorKitEx();
// override the Swing default CSS to make the HTMLEditorKit use the
// same font as the rest of the UI.
// XXX the style sheet is shared by all HTMLEditorKits. We must
// detect if it has been tweaked by ourselves or someone else
// (code completion javadoc popup for example) and avoid doing the
// same thing again
StyleSheet css = htmlkit.getStyleSheet();
if (css.getStyleSheets() == null) {
StyleSheet css2 = new StyleSheet();
Font f = new JList().getFont();
int size = f.getSize();
css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
.append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
css2.addStyleSheet(css);
htmlkit.setStyleSheet(css2);
}
setEditorKit(htmlkit);
addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent hlevt) {
if (EventType.ACTIVATED == hlevt.getEventType()) {
if (hlevt.getURL () != null) {
Utilities.showURL(hlevt.getURL());
}
}
}
});
setEditable(false);
setPreferredSize(new Dimension(300, 80));
RP.post(new Runnable() {
@Override
public void run() {
getAccessibleContext ().setAccessibleName (
NbBundle.getMessage (DetailsPanel.class, "ACN_DetailsPanel")); // NOI18N
}
});
putClientProperty( JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE );
}
示例5: validate
import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
private static void validate() throws Exception {
AppContext appContext = AppContext.getAppContext();
assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");
// Spoil hash value
DTD invalidDtd = DTD.getDTD("invalid DTD");
DTD.putDTDHash(DTD_KEY, invalidDtd);
assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");
Object dtdKey = getParserDelegator_DTD_KEY();
assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");
// Init default DTD
new ParserDelegator();
Object dtdValue = appContext.get(dtdKey);
assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");
// Try reinit default DTD
new ParserDelegator();
assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
if (styleSheet == null) {
// First AppContext
styleSheet = htmlEditorKit.getStyleSheet();
assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
} else {
assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
}
}