本文整理汇总了Java中javax.swing.JEditorPane.setText方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.setText方法的具体用法?Java JEditorPane.setText怎么用?Java JEditorPane.setText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addClassNameEditorCC
import javax.swing.JEditorPane; //导入方法依赖的package包/类
static Pair<JScrollPane, JEditorPane> addClassNameEditorCC(String mimeType, JComponent comp, String className, String tooltipText) {
JComponent [] editorComponents = Utilities.createSingleLineEditor(mimeType);
JScrollPane sle = (JScrollPane) editorComponents[0];
JEditorPane epClassName = (JEditorPane) editorComponents[1];
epClassName.setText(className);
if (comp != null) {
java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
comp.add(sle, gridBagConstraints);
}
sle.setToolTipText(tooltipText);
epClassName.setToolTipText(tooltipText);
return Pair.<JScrollPane, JEditorPane>of(sle, epClassName);
}
示例2: getContentHeight
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Calculates the preferred height of an editor pane with the given fixed width for the
* specified string.
*
* @param comment
* the annotation comment string
* @param width
* the width of the content
* @return the preferred height given the comment
*/
public static int getContentHeight(final String comment, final int width) {
if (comment == null) {
throw new IllegalArgumentException("comment must not be null!");
}
JEditorPane dummyEditorPane = new JEditorPane("text/html", "");
dummyEditorPane.setText(comment);
dummyEditorPane.setBorder(null);
dummyEditorPane.setSize(width, Short.MAX_VALUE);
// height is not exact. Multiply by magic number to get a more fitting value...
if (SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX
|| SystemInfoUtilities.getOperatingSystem() == OperatingSystem.UNIX
|| SystemInfoUtilities.getOperatingSystem() == OperatingSystem.SOLARIS) {
return (int) (dummyEditorPane.getPreferredSize().getHeight() * 1.05f);
} else {
return (int) dummyEditorPane.getPreferredSize().getHeight();
}
}
示例3: showLicense
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Brings up a dialog that displays the license.
*/
private void showLicense() {
JDialog dialog = new JDialog(this, resources.getString("dialog.license.title"));
final JEditorPane text = new JEditorPane();
try {
URL url = getClass().getResource("GNULicense.txt");
text.setPage(url);
} catch (Exception el) {
text.setText(resources.getString("dialog.license.error"));
}
text.setEditable(false);
JScrollPane sp = new JScrollPane(text);
sp.setPreferredSize(new Dimension(650, 500));
dialog.getContentPane().add(sp);
dialog.setLocation(getX() + getWidth() - 200, getY() + 50);
dialog.pack();
dialog.setVisible(true);
}
示例4: 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;
}
示例5: createComponent
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public JComponent createComponent() {
JScrollPane pane = new JScrollPane();
editorPane = new JEditorPane();
pane.setViewportView(editorPane);
if (scriptPath.endsWith(".js"))
editorPane.setContentType("text/javascript");
byte[] bs = framework.getEngine().getStream(scriptPath);
if (bs == null)
bs = new byte[]{};
try {
editorPane.setText(new String(bs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (!saveScriptAction.isEnabled())
editorPane.setEditable(false);
return pane;
}
示例6: MyFrame
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public MyFrame() {
JEditorPane editpane = new JEditorPane();
editpane.setEditable(false);
editpane.setText(content);
editpane.setCaretPosition(0);
JScrollPane scrollpane = new JScrollPane(editpane);
add(scrollpane);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setSize(new Dimension(200, 200));
bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
setResizable(false);
setVisible(true);
}
示例7: testMultiDocs
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testMultiDocs() throws Exception {
JEditorPane pane = new JEditorPane();
pane.setText("abc ax ec ajo");
JFrame frame = new JFrame();
frame.getContentPane().add(pane);
frame.pack(); // Allows to EditorRegistry.register() to make an item in the component list
EditorApiPackageAccessor.get().setIgnoredAncestorClass(JEditorPane.class);
EditorApiPackageAccessor.get().register(pane);
Document doc = new PlainDocument();
WordMatch wordMatch = WordMatch.get(doc);
// 012345678901234567890123456789
doc.insertString(0, "abc a x ahoj", null);
int docLen = doc.getLength();
int offset = 5;
wordMatch.matchWord(offset, false);
compareText(doc, offset - 1, "abc ", docLen + 2);
wordMatch.matchWord(offset, false);
compareText(doc, offset - 1, "ahoj ", docLen + 3);
wordMatch.matchWord(offset, false);
compareText(doc, offset - 1, "ax ", docLen + 1);
wordMatch.matchWord(offset, false);
compareText(doc, offset - 1, "ajo ", docLen + 2);
wordMatch.matchWord(offset, false);
compareText(doc, offset - 1, "ajo ", docLen + 2);
pane.setText(""); // Ensure this doc would affect WordMatch for other docs
}
示例8: refreshPreview
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public @Override void refreshPreview() {
JEditorPane pane = (JEditorPane) getPreviewComponent();
pane.getDocument().putProperty(SimpleValueNames.TEXT_LINE_WRAP, ""); //NOI18N
pane.getDocument().putProperty(SimpleValueNames.TAB_SIZE, ""); //NOI18N
pane.getDocument().putProperty(SimpleValueNames.INDENT_SHIFT_WIDTH, prefs.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, 4));
pane.getDocument().putProperty(SimpleValueNames.SPACES_PER_TAB, prefs.getInt(SimpleValueNames.SPACES_PER_TAB, 4));
pane.getDocument().putProperty(SimpleValueNames.TEXT_LIMIT_WIDTH, ""); //NOI18N
pane.setText(previewText);
final Document doc = pane.getDocument();
if (doc instanceof BaseDocument) {
final Reformat reformat = Reformat.get(doc);
reformat.lock();
try {
((BaseDocument) doc).runAtomic(new Runnable() {
public @Override void run() {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Refreshing preview: expandTabs=" + IndentUtils.isExpandTabs(doc) //NOI18N
+ ", indentLevelSize=" + IndentUtils.indentLevelSize(doc) //NOI18N
+ ", tabSize=" + IndentUtils.tabSize(doc) //NOI18N
+ ", mimeType='" + doc.getProperty("mimeType") + "'" //NOI18N
+ ", doc=" + s2s(doc)); //NOI18N
}
try {
reformat.reformat(0, doc.getLength());
} catch (BadLocationException ble) {
LOG.log(Level.WARNING, null, ble);
}
}
});
} finally {
reformat.unlock();
}
} else {
LOG.warning("Can't format " + doc + "; it's not BaseDocument."); //NOI18N
}
}
示例9: redraw
import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public void redraw() {
// Redraws only if data has changed - Bertoli Marco
if (!redrawNeeded)
return;
if (data.hasResults() && data.areResultsOK()
&& data.getResults().getSaturationSectors().size() > 0) {
if (data.getClasses() == 2) {
this.removeAll();
s2dp = new Sectors2DGraph(data);
this.setLayout(new BorderLayout());
this.add(new JabaCanvas(s2dp), BorderLayout.CENTER);
this.add(new JLabel(JabaConstants.DESCRIPITION_GRAPH),
BorderLayout.PAGE_END);
repaint();
} else if (data.getClasses() == 3) {
this.removeAll();
Sectors3DGraph s3dp = new Sectors3DGraph(data);
this.setLayout(new BorderLayout());
this.add(new JabaCanvas(s3dp), BorderLayout.CENTER);
this.add(new JLabel(JabaConstants.DESCRIPITION_GRAPH),
BorderLayout.PAGE_END);
repaint();
}
} else {
this.removeAll();
JEditorPane synView = new JTextPane();
synView.setContentType("text/html");
synView.setEditable(false);
JScrollPane synScroll = new JScrollPane(synView);
synScroll
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
synScroll
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
synView.setText("<html><body><center><font face=\"bold\" size=\"3\">Saturation Sectors will be here displayed once you solve the model.</font></center></body></html>");
this.add(synScroll, BorderLayout.CENTER);
}
redrawNeeded = false;
}
示例10: showHelp
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* Brings up a window with a scrolling text pane that display the help
* information.
*/
private void showHelp() {
JDialog dialog = new JDialog(this, resources.getString("dialog.help.title"));
final JEditorPane helpText = new JEditorPane();
try {
URL url = getClass().getResource("GridWorldHelp.html");
helpText.setPage(url);
} catch (Exception eh) {
helpText.setText(resources.getString("dialog.help.error"));
}
helpText.setEditable(false);
helpText.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent ev) {
if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
try {
helpText.setPage(ev.getURL());
} catch (Exception ex) {
}
}
});
JScrollPane sp = new JScrollPane(helpText);
sp.setPreferredSize(new Dimension(650, 500));
dialog.getContentPane().add(sp);
dialog.setLocation(getX() + getWidth() - 200, getY() + 50);
dialog.pack();
dialog.setVisible(true);
}
示例11: redraw
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void redraw() {
// We redraw only if data has changed - Sebastiano Spicuglia
if (!redrawNeeded)
return;
this.removeAll();
if (data.hasResults() && data.areResultsOK()
&& data.getResults().getSaturationSectors().size() > 0) {
if (data.getClasses() == 2) {
this.removeAll();
this.setLayout(new GridLayout(2, 1));
JPanel tmp = new JPanel(new GridLayout(1, 2));
tmp.add(new JabaCanvas(new Sectors2DGraph(data)));
tmp.add(new JabaCanvas(new Convex2DGraph(data, mainWin)));
this.add(tmp);
this.add(new JabaCanvas(new PerformanceIndices2DGraph(data)));
repaint();
} else if (data.getClasses() == 3) {
this.removeAll();
this.setLayout(new GridLayout(1, 2));
this.add(new JabaCanvas(new Sectors3DGraph(data)));
this.add(new JabaCanvas(new Convex3DGraph(data, mainWin)));
repaint();
}
} else {
JEditorPane synView = new JTextPane();
synView.setContentType("text/html");
synView.setEditable(false);
JScrollPane synScroll = new JScrollPane(synView);
synScroll
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
synScroll
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
synView.setText("<html><body><center><font face=\"bold\" size=\"3\">Graphs will be here displayed once you solve the model.</font></center></body></html>");
this.add(synScroll);
repaint();
}
redrawNeeded = false;
}
示例12: redraw
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void redraw() {
// Redraws only if data has changed - Bertoli Marco
if (old_data == data) {
return;
} else {
old_data = data;
}
if (data.hasResults() && data.areResultsOK() && data.getResults().size() > 0) {
if (data.getClasses() == 2) {
this.removeAll();
Sectors2DPanel s2dp = new Sectors2DPanel(data.getResults(), data.getClassNames());
this.add(s2dp);
repaint();
} else if (data.getClasses() == 3) {
this.removeAll();
Sectors3DPanel s3dp = new Sectors3DPanel(data.getResults(), data.getClassNames());
this.add(s3dp);
repaint();
}
} else {
this.removeAll();
JEditorPane synView = new JTextPane();
synView.setContentType("text/html");
synView.setEditable(false);
JScrollPane synScroll = new JScrollPane(synView);
synScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
synScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
synView
.setText("<html><body><center><font face=\"bold\" size=\"3\">Saturation Sectors will be here displayed once you solve the model.</font></center></body></html>");
this.add(synScroll);
}
}
示例13: getHardwareReportComponent
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public static JComponent getHardwareReportComponent(CLPlatform platform) {
List<Map<String, Object>> list = listInfos(platform);
final String html = toHTML(list);
JEditorPane ed = new JEditorPane();
ed.setContentType("text/html");
ed.setText(html);
ed.setEditable(false);
JPanel ret = new JPanel(new BorderLayout());
ret.add("Center", new JScrollPane(ed));
final String fileName = "HardwareReport.html";
JButton bWrite = new JButton("Save " + fileName + "...");
bWrite.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog((Frame)null, "Save " + fileName, FileDialog.SAVE);
fd.setFile(fileName);
fd.setVisible(true);
if (fd.getFile() == null)
return;
try {
File file = new File(new File(fd.getDirectory()), fd.getFile());
file.getParentFile().mkdirs();
Writer w = new OutputStreamWriter(new FileOutputStream(file), "utf-8");
w.write(html);
w.close();
Platform.show(file);
} catch (Throwable ex) {
SetupUtils.exception(ex);
}
}
});
ret.add("South", bWrite);
return ret;
}
示例14: 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);
}
示例15: getPane
import javax.swing.JEditorPane; //导入方法依赖的package包/类
protected JEditorPane getPane(String text) throws Exception {
if (!SwingUtilities.isEventDispatchThread()) {
fail("You must run this test from the event dispatch thread! To do that, add @Override protected boolean runInEQ() { return true } from your testcase!");
}
String BEGIN = "$start$"; // NOI18N
String END = "$end$"; // NOI18N
int sourceStartPos = text.indexOf(BEGIN);
int caretPos = -1;
int sourceEndPos = -1;
if (sourceStartPos != -1) {
text = text.substring(0, sourceStartPos) + text.substring(sourceStartPos+BEGIN.length());
sourceEndPos = text.indexOf(END);
assertTrue(sourceEndPos != -1);
text = text.substring(0, sourceEndPos) + text.substring(sourceEndPos+END.length());
} else {
caretPos = text.indexOf('^');
if (caretPos != -1) {
text = text.substring(0, caretPos) + text.substring(caretPos+1);
}
}
JEditorPane pane = new JEditorPane();
pane.setContentType(getPreferredMimeType());
final NbEditorKit kit = ((NbEditorKit)getEditorKit(getPreferredMimeType()));
Thread preload = new Thread(new Runnable() {
@Override
public void run() {
// Preload actions and other stuff
if (kit instanceof Callable) {
try {
((Callable) kit).call();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
kit.getActions();
}
});
preload.start();
preload.join();
pane.setEditorKit(kit);
pane.setText(text);
BaseDocument bdoc = (BaseDocument)pane.getDocument();
bdoc.putProperty(org.netbeans.api.lexer.Language.class, getPreferredLanguage().getLexerLanguage());
bdoc.putProperty("mimeType", getPreferredMimeType());
//bdoc.insertString(0, text, null);
if (sourceStartPos != -1) {
assertTrue(sourceEndPos != -1);
pane.setSelectionStart(sourceStartPos);
pane.setSelectionEnd(sourceEndPos);
} else if (caretPos != -1) {
pane.getCaret().setDot(caretPos);
}
pane.getCaret().setSelectionVisible(true);
return pane;
}