本文整理汇总了Java中javax.swing.JEditorPane.setEditorKit方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.setEditorKit方法的具体用法?Java JEditorPane.setEditorKit怎么用?Java JEditorPane.setEditorKit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.setEditorKit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getErrorMessage
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private JEditorPane getErrorMessage() {
JEditorPane errorMsg = new JEditorPane();
errorMsg.setEditable(false);
errorMsg.setPreferredSize(new Dimension(700, 130));
errorMsg.setBackground(null);
// Text font
Font font = new Font("Sans", Font.PLAIN, 6);
errorMsg.setFont(font);
// Handle HTML
errorMsg.setEditorKit(new HTMLEditorKit());
errorMsg.addHyperlinkListener(this);
errorMsg.setText(ERROR_MSG);
return errorMsg;
}
示例2: configureEditor
import javax.swing.JEditorPane; //导入方法依赖的package包/类
void configureEditor(JEditorPane editor) {
final Dictionary<URL, Image> imageCache = ((SwingPlatform) document.getPlatform()).imageCache;
editor.setEditorKit(new HTMLEditorKit() {
@Override
public javax.swing.text.Document createDefaultDocument() {
HTMLDocument result = (HTMLDocument) super.createDefaultDocument();
try {
result.setBase(document.getUrl().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
result.putProperty("imageCache", imageCache);
return result;
}
});
editor.setMargin(new Insets(0,0,0,0));
editor.setOpaque(false);
editor.setEditable(false);
}
示例3: testActionContextAncestorsLookupProviderIsPreferred
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Tests that the action context for the context-aware toolbar actions
* is the first Lookup.Provider ancestor.
*/
public void testActionContextAncestorsLookupProviderIsPreferred() throws Exception {
JPanel parent1 = new LookupPanel(Lookups.singleton(new Foo() { }));
JPanel parent2 = new LookupPanel(Lookups.singleton(new Bar() { }));
parent1.add(parent2);
JEditorPane editor = new JEditorPane();
editor.setEditorKit(new NbEditorKit());
parent2.add(editor);
DataObject docDataObject = createDataObject();
assertNotNull(docDataObject);
editor.getDocument().putProperty(Document.StreamDescriptionProperty, docDataObject);
Lookup actionContext = NbEditorToolBar.createActionContext(editor);
assertNotNull(actionContext.lookup(Bar.class));
assertNotNull(actionContext.lookup(Node.class));
assertNull(actionContext.lookup(Foo.class));
}
示例4: testMemoryRelease
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@RandomlyFails
public void testMemoryRelease() throws Exception { // Issue #147984
org.netbeans.junit.Log.enableInstances(Logger.getLogger("TIMER"), "CodeTemplateInsertHandler", Level.FINEST);
JEditorPane pane = new JEditorPane();
NbEditorKit kit = new NbEditorKit();
pane.setEditorKit(kit);
Document doc = pane.getDocument();
assertTrue(doc instanceof BaseDocument);
CodeTemplateManager mgr = CodeTemplateManager.get(doc);
String templateText = "Test with parm ";
CodeTemplate ct = mgr.createTemporary(templateText + " ${a}");
ct.insert(pane);
assertEquals(templateText + " a", doc.getText(0, doc.getLength()));
// Send Enter to stop editing
KeyEvent enterKeyEvent = new KeyEvent(pane, KeyEvent.KEY_PRESSED,
EventQueue.getMostRecentEventTime(),
0, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED);
SwingUtilities.processKeyBindings(enterKeyEvent);
// CT editing should be finished
org.netbeans.junit.Log.assertInstances("CodeTemplateInsertHandler instances not GCed");
}
示例5: testPlainEditorKits
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testPlainEditorKits() {
// VIS: JEditorPane when constructed contains javax.swing.JEditorPane$PlainEditorKit
// and calling JEP.setContenetType("text/plain") has no effect. IMO this is probably
// a defect in JDK, becuase JEP should always honour its EditorKit registry.
JEditorPane pane = new JEditorPane();
pane.setEditorKit(new DefaultEditorKit() {
public @Override String getContentType() {
return "text/whatever";
}
});
setContentTypeInAwt(pane, "text/plain");
// Test JDK kit
EditorKit kitFromJdk = pane.getEditorKit();
assertNotNull("Can't find JDK kit for text/plain", kitFromJdk);
assertEquals("The kit for text/plain should not be from JDK",
"org.netbeans.modules.editor.plain.PlainKit", kitFromJdk.getClass().getName());
// Test Netbeans kit
EditorKit kitFromNb = CloneableEditorSupport.getEditorKit("text/plain");
assertNotNull("Can't find Nb kit for text/plain", kitFromNb);
assertEquals("Wrong Nb kit for text/plain",
"org.netbeans.modules.editor.plain.PlainKit", kitFromNb.getClass().getName());
}
示例6: mxCellEditor
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
*
*/
public mxCellEditor(mxGraphComponent graphComponent)
{
this.graphComponent = graphComponent;
// Creates the plain text editor
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
textArea.setOpaque(false);
// Creates the HTML editor
editorPane = new JEditorPane();
editorPane.setOpaque(false);
editorPane.setBackground(new Color(0,0,0,0));
editorPane.setContentType("text/html");
// Workaround for inserted linefeeds in HTML markup with
// lines that are longar than 80 chars
editorPane.setEditorKit(new NoLinefeedHtmlEditorKit());
// Creates the scollpane that contains the editor
// FIXME: Cursor not visible when scrolling
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.getViewport().setOpaque(false);
scrollPane.setVisible(false);
scrollPane.setOpaque(false);
// Installs custom actions
editorPane.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
textArea.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
editorPane.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
textArea.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
// Remembers the action map key for the enter keystroke
editorEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
textEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
}
示例7: FlickrSettingsPanel
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public FlickrSettingsPanel()
{
apiKey = new JTextField();
apiSharedSecret = new JTextField();
// Yuck, this seems to be the minimal amount of code to get a clickable
// and styled link
// (copied from the Cron link in the scheduler)
JEditorPane apiKeyHelp = new JEditorPane();
apiKeyHelp.setEditorKit(new HTMLEditorKit());
apiKeyHelp.setDocument(new HTMLDocument());
apiKeyHelp.setEditable(false);
apiKeyHelp.setText("<html><head><style>" + "<!--a{color:#0000cc;text-decoration: none;}//--></style></head>"
+ "<body>" + getString("settings.label.apikeyhelp"));
apiKeyHelp.addHyperlinkListener(new HyperlinkListener()
{
@Override
public void hyperlinkUpdate(HyperlinkEvent e)
{
if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
{
getClientService().showDocument(e.getURL(), null);
}
}
});
apiKeyHelp.setBackground(new JPanel().getBackground());
add(apiKeyHelp, "span 2");
add(new JLabel(getString("settings.label.apikey")));
add(apiKey);
add(new JLabel(getString("settings.label.apisharedsecret")));
add(apiSharedSecret);
}
示例8: testIndentActions
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testIndentActions() {
// Must run in AWT thread (BaseKit.install() checks for that)
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
testIndentActions();
}
}
);
return;
}
assertTrue(SwingUtilities.isEventDispatchThread());
TestIndentTask.TestFactory factory = new TestIndentTask.TestFactory();
MockServices.setServices(MockMimeLookup.class);
MockMimeLookup.setInstances(MimePath.parse(MIME_TYPE), factory);
TestKit kit = new TestKit();
JEditorPane pane = new JEditorPane();
pane.setEditorKit(kit);
assertEquals(MIME_TYPE, pane.getDocument().getProperty("mimeType"));
//doc.putProperty("mimeType", MIME_TYPE);
// Test insert new line action
Action a = kit.getActionByName(BaseKit.insertBreakAction);
assertNotNull(a);
a.actionPerformed(new ActionEvent(pane, 0, ""));
// Check that the factory was used
assertTrue(TestIndentTask.TestFactory.lastCreatedTask.indentPerformed);
// Test reformat action
a = kit.getActionByName(BaseKit.formatAction);
assertNotNull(a);
a.actionPerformed(new ActionEvent(pane, 0, ""));
}
示例9: ResultPanelOutput
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Creates a new instance of ResultPanelOutput
*/
ResultPanelOutput(ResultDisplayHandler displayHandler) {
super();
if (LOG) {
System.out.println("ResultPanelOutput.<init>");
}
textPane = new JEditorPane();
textPane.setFont(new Font("monospaced", Font.PLAIN, getFont().getSize()));
textPane.setEditorKit(new OutputEditorKit());
textPane.setEditable(false);
textPane.getCaret().setVisible(true);
textPane.getCaret().setBlinkRate(0);
textPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
setViewportView(textPane);
/*
* On GTK L&F, background of the text pane is gray, even though it is
* white on a JTextArea. The following is a hack to fix it:
*/
Color background = UIManager.getColor("TextPane.background"); //NOI18N
if (background != null) {
textPane.setBackground(background);
}
doc = textPane.getDocument();
AccessibleContext ac = textPane.getAccessibleContext();
ac.setAccessibleName(NbBundle.getMessage(getClass(),
"ACSN_OutputTextPane"));//NOI18N
ac.setAccessibleDescription(NbBundle.getMessage(getClass(),
"ACSD_OutputTextPane"));//NOI18N
this.displayHandler = displayHandler;
}
示例10: mxCellEditor
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
*
*/
public mxCellEditor(mxGraphComponent graphComponent) {
this.graphComponent = graphComponent;
// Creates the plain text editor
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
textArea.setOpaque(false);
// Creates the HTML editor
editorPane = new JEditorPane();
editorPane.setOpaque(false);
editorPane.setBackground(new Color(0, 0, 0, 0));
editorPane.setContentType("text/html");
// Workaround for inserted linefeeds in HTML markup with
// lines that are longar than 80 chars
editorPane.setEditorKit(new NoLinefeedHtmlEditorKit());
// Creates the scollpane that contains the editor
// FIXME: Cursor not visible when scrolling
scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createEmptyBorder());
scrollPane.getViewport().setOpaque(false);
scrollPane.setVisible(false);
scrollPane.setOpaque(false);
// Installs custom actions
editorPane.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
textArea.getActionMap().put(CANCEL_EDITING, cancelEditingAction);
editorPane.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
textArea.getActionMap().put(SUBMIT_TEXT, textSubmitAction);
// Remembers the action map key for the enter keystroke
editorEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
textEnterActionMapKey = editorPane.getInputMap().get(enterKeystroke);
}
示例11: testActionContextNullWhenNoDataObject
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Tests that the action context for the context-aware toolbar actions
* contains the editor pane if there is no Lookup.Provider ancestor and no DataObject
* corresponding to the current document.
*/
public void testActionContextNullWhenNoDataObject() {
JPanel parent = new JPanel();
JEditorPane editor = new JEditorPane();
editor.setEditorKit(new NbEditorKit());
parent.add(editor);
Lookup actionContext = NbEditorToolBar.createActionContext(editor);
// changed when fixing #127757
//assertNull(actionContext);
assertNotNull(actionContext);
Collection<?> all = actionContext.lookupAll(Object.class);
assertEquals("Expecting singleton Lookup", 1, all.size());
assertSame("Expecting the editor pane", editor, all.iterator().next());
}
示例12: testActionContextLookupContainsNodeOnlyOnce
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Tests that the action context for the context-aware toolbar actions
* contains the node corresponding to the current document only once, even
* though the node is both contained in an ancestor Lookup.Provider and
* obtained as the node delegate of the DataObject of the current document.
*/
public void testActionContextLookupContainsNodeOnlyOnce() throws Exception {
DataObject docDataObject = createDataObject();
assertNotNull(docDataObject);
JPanel parent = new LookupPanel(Lookups.fixed(new Object[] { new Bar() { }, docDataObject.getNodeDelegate().getLookup() }));
JEditorPane editor = new JEditorPane();
editor.setEditorKit(new NbEditorKit());
parent.add(editor);
editor.getDocument().putProperty(Document.StreamDescriptionProperty, docDataObject);
Lookup actionContext = NbEditorToolBar.createActionContext(editor);
assertNotNull(actionContext.lookup(Bar.class));
assertNotNull(actionContext.lookup(Node.class));
assertEquals(1, actionContext.lookup(new Lookup.Template(Node.class)).allInstances().size());
}
示例13: createEditor
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private JEditorPane createEditor() {
String mimeType = "text/x-oql"; // NOI18N
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(MimeLookup.getLookup(mimeType).lookup(EditorKit.class));
TokenHierarchy th = TokenHierarchy.get(editorPane.getDocument());
th.addTokenHierarchyListener(new TokenChangeListener(editorPane.getDocument()));
return editorPane;
}
示例14: HelpWindow
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public HelpWindow(String title, URL contents) {
super(title);
setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
setJMenuBar(MenuManager.getInstance().getMenuBarFor(this));
pane = new JEditorPane();
pane.setEditable(false);
pane.addHyperlinkListener(this);
/*
* Allow <src> tag to display images from the module DataArchive
* where no pathname included in the image name.
*/
pane.setContentType("text/html"); //$NON-NLS-1$
XTMLEditorKit myHTMLEditorKit = new HtmlChart.XTMLEditorKit();
pane.setEditorKit(myHTMLEditorKit);
JScrollPane scroll = new ScrollPane(pane);
add(scroll);
update(contents);
pack();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = Math.max(d.width / 2, getSize().width);
int height = Math.max(d.height / 2, getSize().height);
width = Math.min(width, d.width * 2 / 3);
height = Math.min(height, d.height * 2 / 3);
setSize(width, height);
setLocation(d.width / 2 - width / 2, 0);
}
示例15: DialogHelpWindow
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public DialogHelpWindow(String title, URL contents, Dialog parent) {
super(parent);
setTitle(title);
setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
//setJMenuBar(MenuManager.getInstance().getMenuBarFor(this));
pane = new JEditorPane();
pane.setEditable(false);
pane.addHyperlinkListener(this);
/*
* Allow <src> tag to display images from the module DataArchive
* where no pathname included in the image name.
*/
pane.setContentType("text/html"); //$NON-NLS-1$
XTMLEditorKit myHTMLEditorKit = new HtmlChart.XTMLEditorKit();
pane.setEditorKit(myHTMLEditorKit);
JScrollPane scroll = new ScrollPane(pane);
add(scroll);
update(contents);
pack();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int width = Math.max(d.width / 2, getSize().width);
int height = Math.max(d.height / 2, getSize().height);
width = Math.min(width, d.width * 2 / 3);
height = Math.min(height, d.height * 2 / 3);
setSize(width, height);
setLocation(d.width / 2 - width / 2, 0);
}