Java Code Examples for javax.swing.JEditorPane#setFont()
The following examples show how to use
javax.swing.JEditorPane#setFont() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebStorePanel.java From netbeans with Apache License 2.0 | 6 votes |
private double getAdjustedHeight(){ JEditorPane fakePane = new JEditorPane(); fakePane.setEditable(false); fakePane.setBorder(null); fakePane.setContentType("text/html"); // NOI18N fakePane.setFont(description.getFont()); Dimension size = description.getPreferredSize(); size.setSize( size.getWidth(), Short.MAX_VALUE); fakePane.setSize( size); fakePane.setText(description.getText()); Font font = description.getFont(); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument)fakePane.getDocument()).getStyleSheet().addRule(bodyRule); return fakePane.getPreferredSize().getHeight(); }
Example 2
Source File: BrokenProjectInfo.java From netbeans with Apache License 2.0 | 6 votes |
static JEditorPane getErrorPane(String reason) { JEditorPane errorLabel = new JEditorPane(); JLabel infoLabel = new JLabel(); errorLabel.setContentType("text/html"); // NOI18N errorLabel.setEditable(false); errorLabel.setForeground(UIManager.getDefaults().getColor("nb.errorForeground")); errorLabel.setRequestFocusEnabled(false); errorLabel.setBackground(infoLabel.getBackground()); errorLabel.setFont(infoLabel.getFont()); errorLabel.addHyperlinkListener(new BrokenProjectInfo()); errorLabel.setText(reason); return errorLabel; }
Example 3
Source File: EditorPanel.java From nextreports-designer with Apache License 2.0 | 6 votes |
public EditorPanel(int width, int height) { super(); editorPane = new JEditorPane(); editorPane.setEditorKit(new BaseEditorKit()); // must set a monospaced font, otherwise the caret position will be incorrect !! // but 'monospaced' font is ugly and I use 'Courier New'; you must install on Linux 'ttf-mscorefonts-installer' // (Installer for Microsoft TrueType core fonts) editorPane.setFont(new Font("Courier New", Font.PLAIN, 12)); CurrentLineHighlighter.install(editorPane); scrollPane = new EditorScrollPane(width, height, editorPane, true, null); setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); editorPane.requestFocus(); }
Example 4
Source File: DefaultSyntaxKit.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
/** * Install the View on the given EditorPane. This is called by Swing and * can be used to do anything you need on the JEditorPane control. Here * I set some default Actions. * * @param editorPane */ @Override public void install(JEditorPane editorPane) { super.install(editorPane); // get our font String fontName = getProperty("DefaultFont"); Font font = DEFAULT_FONT; if (fontName != null) { font = Font.decode(fontName); } editorPane.setFont(font); Configuration conf = getConfig(); Color caretColor = conf.getColor(CONFIG_CARETCOLOR, Color.BLACK); editorPane.setCaretColor(caretColor); Color selectionColor = getConfig().getColor(CONFIG_SELECTION, new Color(0x99ccff)); editorPane.setSelectionColor(selectionColor); addActions(editorPane); addComponents(editorPane); addPopupMenu(editorPane); }
Example 5
Source File: AboutDialog.java From jeveassets with GNU General Public License v2.0 | 6 votes |
private JEditorPane createEditorPane(final boolean addBorder, final String text) { JEditorPane jEditorPane = new JEditorPane("text/html", "<html><div style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11pt; white-space: nowrap;\">" + text + "</div>" ); jEditorPane.setEditable(false); jEditorPane.setFocusable(false); jEditorPane.setOpaque(false); jEditorPane.setFont(jPanel.getFont()); jEditorPane.addHyperlinkListener(DesktopUtil.getHyperlinkListener(getDialog())); if (addBorder) { jEditorPane.setBorder(BorderFactory.createEmptyBorder(11, 11, 11, 11)); } return jEditorPane; }
Example 6
Source File: AnnotationDrawUtils.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * 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, final Font font) { if (comment == null) { throw new IllegalArgumentException("comment must not be null!"); } // do not create Swing components for headless mode if (RapidMiner.getExecutionMode().isHeadless()) { return 0; } JEditorPane dummyEditorPane = new JEditorPane("text/html", ""); dummyEditorPane.setText(comment); dummyEditorPane.setBorder(null); dummyEditorPane.setSize(width, Short.MAX_VALUE); dummyEditorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); dummyEditorPane.setFont(font); // 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(); } }
Example 7
Source File: GithubPanel.java From MakeLobbiesGreatAgain with MIT License | 5 votes |
/** * Creates the new Panel and parses the supplied HTML. <br> * <b> Supported Github Markdown: </b><i> Lists (unordered), Links, Images, Bold ('**' and '__'), Strikethrough, & Italics. </i> * * @param currentVersion The version of the Jar currently running. */ public GithubPanel(double currentVersion) { this.version = currentVersion; setTitle("MLGA Update"); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); parseReleases(); } catch (Exception e1) { e1.printStackTrace(); } if (updates <= 0) { return; } ed = new JEditorPane("text/html", html); ed.setEditable(false); ed.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); ed.setFont(new Font("Helvetica", 0, 12)); ed.addHyperlinkListener(he -> { // Listen to link clicks and open them in the browser. if (he.getEventType() == EventType.ACTIVATED && Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(he.getURL().toURI()); System.exit(0); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } } }); final JScrollPane scrollPane = new JScrollPane(ed); scrollPane.setPreferredSize(new Dimension(1100, 300)); add(scrollPane); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); setLocationRelativeTo(null); }
Example 8
Source File: BannerPanel.java From nextreports-designer with Apache License 2.0 | 5 votes |
public BannerPanel() { setBorder(new CompoundBorder(new EtchedBorder(), new EmptyBorder(3, 3, 3, 3))); setOpaque(true); setBackground(UIManager.getColor("Table.background")); titleLabel = new JLabel(); titleLabel.setOpaque(false); subtitleLabel = new JEditorPane("text/html", "<html>"); subtitleLabel.setFont(titleLabel.getFont()); LookAndFeelTweaks.makeBold(titleLabel); LookAndFeelTweaks.makeMultilineLabel(subtitleLabel); LookAndFeelTweaks.htmlize(subtitleLabel); iconLabel = new JLabel(); iconLabel.setMinimumSize(new Dimension(50, 50)); setLayout(new BorderLayout()); JPanel nestedPane = new JPanel(); nestedPane.setLayout(new GridBagLayout()); nestedPane.setOpaque(false); nestedPane.add(titleLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); nestedPane.add(new JLabel(""), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); nestedPane.add(subtitleLabel, new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0)); add(BorderLayout.CENTER, nestedPane); add(BorderLayout.EAST, iconLabel); }
Example 9
Source File: BannerPanel.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public BannerPanel() { setBorder( new CompoundBorder(new EtchedBorder(), LookAndFeelTweaks.PANEL_BORDER)); setOpaque(true); setBackground(UIManager.getColor("Table.background")); titleLabel = new JLabel(); titleLabel.setOpaque(false); subtitleLabel = new JEditorPane("text/html", "<html>"); subtitleLabel.setFont(titleLabel.getFont()); LookAndFeelTweaks.makeBold(titleLabel); LookAndFeelTweaks.makeMultilineLabel(subtitleLabel); LookAndFeelTweaks.htmlize(subtitleLabel); iconLabel = new JLabel(); iconLabel.setPreferredSize(new Dimension(50, 50)); setLayout(new BorderLayout()); JPanel nestedPane = new JPanel(new BorderLayout()); nestedPane.setOpaque(false); nestedPane.add("North", titleLabel); nestedPane.add("Center", subtitleLabel); add("Center", nestedPane); add("East", iconLabel); }
Example 10
Source File: AccountImportDialog.java From jeveassets with GNU General Public License v2.0 | 5 votes |
public DonePanel() { jResult = new JLabel(); jResult.setFont(new Font(this.getFont().getName(), Font.BOLD, this.getFont().getSize())); jHelp = new JEditorPane("text/html", ""); //jHelp.setLineWrap(true); //jHelp.setWrapStyleWord(true); jHelp.addHyperlinkListener(DesktopUtil.getHyperlinkListener(getDialog())); jHelp.setFont(this.getFont()); jHelp.setEditable(false); jHelp.setOpaque(false); jHelp.setFocusable(false); jHelp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JScrollPane jScroll = new JScrollPane(jHelp, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jScroll.setBorder(BorderFactory.createLineBorder(this.getBackground().darker(), 1)); cardLayout.setHorizontalGroup( cardLayout.createParallelGroup() .addGroup(cardLayout.createSequentialGroup() .addGap(5) .addComponent(jResult) ) .addComponent(jScroll, 400, 400, 400) ); cardLayout.setVerticalGroup( cardLayout.createSequentialGroup() .addComponent(jResult, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight()) .addComponent(jScroll, 98, 98, 98) ); }
Example 11
Source File: BannerPanel.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public BannerPanel() { setBorder( new CompoundBorder(new EtchedBorder(), LookAndFeelTweaks.PANEL_BORDER)); setOpaque(true); setBackground(UIManager.getColor("Table.background")); titleLabel = new JLabel(); titleLabel.setOpaque(false); subtitleLabel = new JEditorPane("text/html", "<html>"); subtitleLabel.setFont(titleLabel.getFont()); LookAndFeelTweaks.makeBold(titleLabel); LookAndFeelTweaks.makeMultilineLabel(subtitleLabel); LookAndFeelTweaks.htmlize(subtitleLabel); iconLabel = new JLabel(); iconLabel.setPreferredSize(new Dimension(50, 50)); setLayout(new BorderLayout()); JPanel nestedPane = new JPanel(new BorderLayout()); nestedPane.setOpaque(false); nestedPane.add("North", titleLabel); nestedPane.add("Center", subtitleLabel); add("Center", nestedPane); add("East", iconLabel); }
Example 12
Source File: DocumentationUI.java From whyline with MIT License | 5 votes |
public DocumentationUI(WhylineUI whylineUI) { super("documentation", whylineUI); doc = new JEditorPane("text/html", ""); // This makes the pane respect the background, foreground, font. doc.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); doc.setBackground(UI.getControlBackColor()); doc.setForeground(UI.getControlTextColor()); doc.setOpaque(true); doc.setFont(UI.getMediumFont()); doc.setEditable(false); WhylineScrollPane pane = new WhylineScrollPane(doc); pane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); pane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); pane.setBorder(new WhylineControlBorder()); setContent(pane); setMinimumSize(new Dimension(UI.getDefaultInfoPaneWidth(whylineUI), 0)); doc.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) Util.openURL(e.getURL().toString()); } }); }
Example 13
Source File: RubyConsole.java From ramus with GNU General Public License v3.0 | 5 votes |
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; }
Example 14
Source File: ResultPanelOutput.java From netbeans with Apache License 2.0 | 5 votes |
/** * 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; }
Example 15
Source File: JavaViewHierarchyRandomTest.java From netbeans with Apache License 2.0 | 4 votes |
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); } } }); }
Example 16
Source File: JdotxtPreferencesDialog.java From jdotxt with GNU General Public License v3.0 | 4 votes |
private JPanel getHelpPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBackground(Color.WHITE); panel.setOpaque(true); JLabel labelIcon = new JLabel(new ImageIcon(JdotxtGUI.icon.getImage().getScaledInstance(64, 64, java.awt.Image.SCALE_SMOOTH))); labelIcon.setVerticalAlignment(SwingConstants.TOP); panel.add(labelIcon, BorderLayout.WEST); labelIcon.setPreferredSize(new Dimension(100, 100)); JPanel panelInfo = new JPanel(); panel.add(panelInfo, BorderLayout.CENTER); panelInfo.setLayout(new BoxLayout(panelInfo, BoxLayout.Y_AXIS)); panelInfo.add(Box.createVerticalStrut(10)); panelInfo.setBackground(Color.WHITE); panelInfo.setOpaque(true); JLabel labelTitle = new JLabel(JdotxtGUI.lang.getWord("jdotxt") + " (Version " + Jdotxt.VERSION + ")"); labelTitle.setFont(JdotxtGUI.fontB.deriveFont(16f)); panelInfo.add(labelTitle); panelInfo.add(Box.createVerticalStrut(20)); JEditorPane textInfo = new JEditorPane(); textInfo.setContentType("text/html"); textInfo.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); textInfo.setFont(JdotxtGUI.fontR); textInfo.setText(JdotxtGUI.lang.getWord("Text_help")); textInfo.setEditable(false); textInfo.setFocusable(false); textInfo.setAlignmentX(Component.LEFT_ALIGNMENT); textInfo.setBorder(BorderFactory.createEmptyBorder()); textInfo.setMaximumSize(textInfo.getPreferredSize()); panelInfo.add(textInfo); panelInfo.add(Box.createVerticalStrut(20)); JLabel labelShortcuts = new JLabel(JdotxtGUI.lang.getWord("Shortcuts")); labelShortcuts.setFont(JdotxtGUI.fontB.deriveFont(14f)); panelInfo.add(labelShortcuts); panelInfo.add(Box.createVerticalStrut(20)); JEditorPane textShortcuts = new JEditorPane(); textShortcuts.setContentType("text/html"); textShortcuts.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); textShortcuts.setFont(JdotxtGUI.fontR); textShortcuts.setText(JdotxtGUI.lang.getWord("Text_shortcuts")); textShortcuts.setEditable(false); textShortcuts.setFocusable(false); textShortcuts.setAlignmentX(Component.LEFT_ALIGNMENT); textShortcuts.setBorder(BorderFactory.createEmptyBorder()); textShortcuts.setMaximumSize(textShortcuts.getPreferredSize()); panelInfo.add(textShortcuts); panelInfo.add(Box.createVerticalGlue()); panel.revalidate(); return panel; }
Example 17
Source File: AccountImportDialog.java From jeveassets with GNU General Public License v2.0 | 4 votes |
public ImportPanel() { JEditorPane jHelp = new JEditorPane("text/html", "<html><body style=\"font-family: " + getFont().getName() + "; font-size: " + getFont().getSize() + "pt\">" + DialoguesAccount.get().shareImportHelp() + "</body></html>"); ((HTMLDocument) jHelp.getDocument()).getStyleSheet().addRule("body { font-family: " + getFont().getFamily() + "; " + "font-size: " + this.getFont().getSize() + "pt; }"); jHelp.setFont(getFont()); jHelp.setEditable(false); jHelp.setFocusable(false); jHelp.setOpaque(false); jImportClipboard = new JButton(DialoguesAccount.get().shareImportClipboard() , Images.EDIT_PASTE.getIcon()); jImportClipboard.setActionCommand(AccountImportAction.SHARE_FROM_CLIPBOARD.name()); jImportClipboard.addActionListener(listener); jImportFile= new JButton(DialoguesAccount.get().shareImportFile(), Images.FILTER_LOAD.getIcon()); jImportFile.setActionCommand(AccountImportAction.SHARE_FROM_FILE.name()); jImportFile.addActionListener(listener); jImport = new JTextArea(); jImport.setFont(getFont()); jImport.setEditable(true); jImport.setFocusable(true); jImport.setOpaque(true); jImport.setLineWrap(true); jImport.setWrapStyleWord(false); JScrollPane jScroll = new JScrollPane(jImport, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); jScroll.setBorder(BorderFactory.createLineBorder(this.getBackground().darker(), 1)); cardLayout.setHorizontalGroup( cardLayout.createParallelGroup() .addComponent(jHelp) .addGroup(cardLayout.createSequentialGroup() .addComponent(jScroll) .addGroup(cardLayout.createParallelGroup() .addComponent(jImportClipboard, Program.getButtonsWidth(), Program.getButtonsWidth(), Program.getButtonsWidth()) .addComponent(jImportFile, Program.getButtonsWidth(), Program.getButtonsWidth(), Program.getButtonsWidth()) ) ) ); cardLayout.setVerticalGroup( cardLayout.createSequentialGroup() .addComponent(jHelp) .addGroup(cardLayout.createParallelGroup() .addComponent(jScroll) .addGroup(cardLayout.createSequentialGroup() .addComponent(jImportClipboard, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight()) .addComponent(jImportFile, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight()) ) ) ); }
Example 18
Source File: ToolTipSupport.java From netbeans with Apache License 2.0 | 4 votes |
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(); /* See NETBEANS-403. It still appears possible to use Escape to close the popup when the focus is in the editor. */ tt.putClientProperty(SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY, true); // 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; }
Example 19
Source File: BaseDocument.java From netbeans with Apache License 2.0 | 4 votes |
/** 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 }
Example 20
Source File: CheckForUpdateAction.java From nextreports-designer with Apache License 2.0 | 4 votes |
private JComponent createPanel(String html) { System.setProperty("awt.useSystemAAFontSettings", "on"); final JEditorPane editorPane = new JEditorPane(); HTMLEditorKit kit = new HTMLEditorKit(); editorPane.setEditorKit(kit); editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); editorPane.setFont(new Font("Arial", Font.PLAIN, 12)); editorPane.setPreferredSize(new Dimension(350, 120)); editorPane.setEditable(false); editorPane.setContentType("text/html"); editorPane.setBackground(new Color(234, 241, 248)); Document doc = kit.createDefaultDocument(); editorPane.setDocument(doc); editorPane.setText(html); // Add Hyperlink listener to process hyperlinks editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) { EventQueue.invokeLater(new Runnable() { public void run() { SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); editorPane.setToolTipText(e.getURL().toExternalForm()); } }); } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) { EventQueue.invokeLater(new Runnable() { public void run() { SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getDefaultCursor()); editorPane.setToolTipText(null); } }); } else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { FileUtil.openUrl(e.getURL().toString(), AboutAction.class); } } }); editorPane.addMouseListener(mouseListener); JScrollPane sp = new JScrollPane(editorPane); return sp; }