本文整理匯總了Java中javax.swing.JEditorPane.setFont方法的典型用法代碼示例。如果您正苦於以下問題:Java JEditorPane.setFont方法的具體用法?Java JEditorPane.setFont怎麽用?Java JEditorPane.setFont使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.setFont方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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;
}
示例3: createComponent
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public JComponent createComponent() {
JPanel panel = new JPanel();
JPanel console = new JPanel();
panel.setLayout(new BorderLayout());
final JEditorPane text = new JTextPane();
text.setMargin(new Insets(8, 8, 8, 8));
text.setCaretColor(new Color(0xa4, 0x00, 0x00));
text.setBackground(new Color(0xf2, 0xf2, 0xf2));
text.setForeground(new Color(0xa4, 0x00, 0x00));
Font font = findFont("Monospaced", Font.PLAIN, 14, new String[]{
"Monaco", "Andale Mono"});
text.setFont(font);
JScrollPane pane = new JScrollPane();
pane.setViewportView(text);
pane.setBorder(BorderFactory.createLineBorder(Color.darkGray));
panel.add(pane, BorderLayout.CENTER);
console.validate();
final TextAreaReadline tar = new TextAreaReadline(text,
getString("Wellcom") + " \n\n");
RubyInstanceConfig config = new RubyInstanceConfig() {
{
//setInput(tar.getInputStream());
//setOutput(new PrintStream(tar.getOutputStream()));
//setError(new PrintStream(tar.getOutputStream()));
setObjectSpaceEnabled(false);
}
};
Ruby runtime = Ruby.newInstance(config);
tar.hookIntoRuntimeWithStreams(runtime);
run(runtime);
return panel;
}
示例4: buildDetail
import javax.swing.JEditorPane; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void buildDetail(String id, JPanel panel) {
if (this.id.equals(id)) return;
panel.setLayout(new MigLayout("wrap 1, center"));
JLabel header = Utility.localizedHeaderLabel(Messages.nameKey(id),
SwingConstants.LEADING, FontLibrary.FontSize.SMALL);
panel.add(header, "align center, wrap 20");
JEditorPane editorPane = new JEditorPane("text/html",
Messages.getDescription(id)) {
@Override
public void paintComponent(Graphics g) {
Graphics2D graphics2d = (Graphics2D) g;
graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
/*
graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
*/
super.paintComponent(graphics2d);
}
};
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
Boolean.TRUE);
editorPane.setFont(panel.getFont());
editorPane.setOpaque(false);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(colopediaPanel);
panel.add(editorPane, "width 95%");
}
示例5: install
import javax.swing.JEditorPane; //導入方法依賴的package包/類
/** Set to a sane font (not proportional!). */
public @Override void install(JEditorPane pane) {
super.install(pane);
pane.setFont(new Font("Monospaced", Font.PLAIN, pane.getFont().getSize() + 1)); //NOI18N
}
示例6: createHtmlTextToolTip
import javax.swing.JEditorPane; //導入方法依賴的package包/類
private JEditorPane createHtmlTextToolTip() {
class HtmlTextToolTip extends JEditorPane {
public @Override void setSize(int width, int height) {
Dimension prefSize = getPreferredSize();
if (width >= prefSize.width) {
width = prefSize.width;
} else { // smaller available width
super.setSize(width, 10000); // the height is unimportant
prefSize = getPreferredSize(); // re-read new pref width
}
if (height >= prefSize.height) { // enough height
height = prefSize.height;
}
super.setSize(width, height);
}
@Override
public void setKeymap(Keymap map) {
//#181722: keymaps are shared among components with the same UI
//a default action will be set to the Keymap of this component below,
//so it is necessary to use a Keymap that is not shared with other components
super.setKeymap(addKeymap(null, map));
}
}
JEditorPane tt = new HtmlTextToolTip();
// setup tooltip keybindings
filterBindings(tt.getActionMap());
tt.getActionMap().put(HIDE_ACTION.getValue(Action.NAME), HIDE_ACTION);
tt.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), HIDE_ACTION.getValue(Action.NAME));
tt.getKeymap().setDefaultAction(NO_ACTION);
Font font = UIManager.getFont(UI_PREFIX + ".font"); // NOI18N
Color backColor = UIManager.getColor(UI_PREFIX + ".background"); // NOI18N
Color foreColor = UIManager.getColor(UI_PREFIX + ".foreground"); // NOI18N
if (font != null) {
tt.setFont(font);
}
if (foreColor != null) {
tt.setForeground(foreColor);
}
if (backColor != null) {
tt.setBackground(backColor);
}
tt.setOpaque(true);
tt.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(tt.getForeground()),
BorderFactory.createEmptyBorder(0, 3, 0, 3)
));
tt.setContentType("text/html"); //NOI18N
return tt;
}
示例7: install
import javax.swing.JEditorPane; //導入方法依賴的package包/類
/** Set to a sane font (not proportional!). */
@Override
public void install(JEditorPane pane) {
super.install(pane);
pane.setFont(new Font("Monospaced", Font.PLAIN, pane.getFont().getSize() + 1)); //NOI18N
}
示例8: testToolTipView
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testToolTipView() throws Exception {
loggingOn();
RandomTestContainer container = createContainer();
final JEditorPane pane = container.getInstance(JEditorPane.class);
final Document doc = pane.getDocument();
doc.putProperty("mimeType", "text/plain");
RandomTestContainer.Context context = container.context();
// ViewHierarchyRandomTesting.disableHighlighting(container);
DocumentTesting.setSameThreadInvoke(context, true); // Do not post to EDT
DocumentTesting.insert(context, 0, "abc\ndef\nghi\n");
final JEditorPane[] toolTipPaneRef = new JEditorPane[1];
final BadLocationException[] excRef = new BadLocationException[1];
final JFrame[] toolTipFrameRef = new JFrame[1];
Runnable tooltipRun = new Runnable() {
@Override
public void run() {
JEditorPane toolTipPane = new JEditorPane();
toolTipPaneRef[0] = toolTipPane;
toolTipPane.setEditorKit(pane.getEditorKit());
try {
Position startPos = doc.createPosition(4); // Line begining
Position endPos = doc.createPosition(8); // Line boundary too
toolTipPane.putClientProperty("document-view-start-position", startPos);
toolTipPane.putClientProperty("document-view-end-position", endPos);
toolTipPane.setDocument(doc);
JFrame toolTipFrame = new JFrame("ToolTip Frame");
toolTipFrameRef[0] = toolTipFrame;
toolTipFrame.getContentPane().add(new JScrollPane(toolTipPane));
toolTipFrame.setSize(100, 100);
toolTipFrame.setVisible(true);
doc.insertString(4, "o", null);
toolTipPane.setFont(new Font("Monospaced", Font.PLAIN, 22)); // Force VH rebuild
toolTipPane.modelToView(6);
doc.remove(3, 3);
doc.insertString(4, "ab", null);
assert (endPos.getOffset() == 8);
doc.remove(7, 2);
toolTipPane.setFont(new Font("Monospaced", Font.PLAIN, 23)); // Force VH rebuild
toolTipPane.modelToView(6);
} catch (BadLocationException ex) {
excRef[0] = ex;
}
}
};
SwingUtilities.invokeAndWait(tooltipRun);
if (excRef[0] != null) {
throw new IllegalStateException(excRef[0]);
}
DocumentTesting.setSameThreadInvoke(context, false);
DocumentTesting.undo(context, 2);
DocumentTesting.undo(context, 1);
DocumentTesting.undo(context, 1);
DocumentTesting.redo(context, 4);
// Hide tooltip's frame
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (toolTipFrameRef[0] != null) {
toolTipFrameRef[0].setVisible(false);
}
}
});
}
示例9: enforceJEditorPaneFont
import javax.swing.JEditorPane; //導入方法依賴的package包/類
/**
* Enforces JEditorPane font.
* Once the content type of a JEditorPane is set to text/html the font on the Pane starts to be managed by Swing.
* This method forces using provided font.
*/
public static void enforceJEditorPaneFont(JEditorPane jEditorPane, Font font) {
jEditorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
jEditorPane.setFont(font);
}