Java Code Examples for javax.swing.plaf.basic.BasicHTML#createHTMLView()
The following examples show how to use
javax.swing.plaf.basic.BasicHTML#createHTMLView() .
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: TabbedPaneHandler.java From darklaf with MIT License | 6 votes |
protected void updateHtmlViews(final int index, final boolean inserted) { String title = ui.tabPane.getTitleAt(index); boolean isHTML = BasicHTML.isHTMLString(title); if (isHTML) { if (ui.htmlViews == null) { // Initialize vector ui.htmlViews = ui.createHTMLVector(); } else { // Vector already exists View v = BasicHTML.createHTMLView(ui.tabPane, title); setHtmlView(v, inserted, index); } } else { // Not HTML if (ui.htmlViews != null) { // Add placeholder setHtmlView(null, inserted, index); } // else nada! } ui.updateMnemonics(); }
Example 2
Source File: CloseTabPaneUI.java From iBioSim with Apache License 2.0 | 6 votes |
@Override public void componentAdded(ContainerEvent e) { JTabbedPane tp = (JTabbedPane) e.getContainer(); Component child = e.getChild(); if (child instanceof UIResource) { return; } int index = tp.indexOfComponent(child); String title = tp.getTitleAt(index); boolean isHTML = BasicHTML.isHTMLString(title); if (isHTML) { if (htmlViews == null) { // Initialize vector htmlViews = createHTMLVector(); } else { // Vector already exists View v = BasicHTML.createHTMLView(tp, title); htmlViews.insertElementAt(v, index); } } else { // Not HTML if (htmlViews != null) { // Add placeholder htmlViews.insertElementAt(null, index); } // else nada! } }
Example 3
Source File: HelpTooltip.java From consulo with Apache License 2.0 | 6 votes |
private Header(boolean obeyWidth) { setFont(deriveHeaderFont(getFont())); setForeground(UIUtil.getToolTipForeground()); if (obeyWidth) { View v = BasicHTML.createHTMLView(this, String.format("<html>%s%s</html>", title, getShortcutAsHTML())); float width = v.getPreferredSpan(View.X_AXIS); isMultiline = isMultiline || width > MAX_WIDTH.get(); setText(width > MAX_WIDTH.get() ? String.format("<html><div width=%d>%s%s</div></html>", MAX_WIDTH.get(), title, getShortcutAsHTML()) : String.format("<html>%s%s</html>", title, getShortcutAsHTML())); setSizeForWidth(width); } else { setText(String.format("<html>%s%s</html>", title, getShortcutAsHTML())); } }
Example 4
Source File: HelpTooltip.java From consulo with Apache License 2.0 | 5 votes |
private Paragraph(String text, boolean hasTitle) { setForeground(hasTitle ? INFO_COLOR : UIUtil.getToolTipForeground()); setFont(deriveDescriptionFont(getFont(), hasTitle)); View v = BasicHTML.createHTMLView(this, String.format("<html>%s</html>", text)); float width = v.getPreferredSpan(View.X_AXIS); isMultiline = isMultiline || width > MAX_WIDTH.get(); setText(width > MAX_WIDTH.get() ? String.format("<html><div width=%d>%s</div></html>", MAX_WIDTH.get(), text) : String.format("<html>%s</html>", text)); setSizeForWidth(width); }
Example 5
Source File: ComponentValidator.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static ComponentPopupBuilder createPopupBuilder(@Nonnull ValidationInfo info, @Nullable Consumer<? super JEditorPane> configurator) { JEditorPane tipComponent = new JEditorPane(); View v = BasicHTML.createHTMLView(tipComponent, String.format("<html>%s</html>", info.message)); String text = v.getPreferredSpan(View.X_AXIS) > MAX_WIDTH.get() ? String.format("<html><body><div width=%d>%s</div><body></html>", MAX_WIDTH.get(), trimMessage(info.message, tipComponent)) : String.format("<html><body><div>%s</div></body></html>", info.message); tipComponent.setContentType("text/html"); tipComponent.setEditable(false); tipComponent.setEditorKit(UIUtil.getHTMLEditorKit()); EditorKit kit = tipComponent.getEditorKit(); if (kit instanceof HTMLEditorKit) { StyleSheet css = ((HTMLEditorKit)kit).getStyleSheet(); css.addRule("a, a:link {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkColor()) + ";}"); css.addRule("a:visited {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkVisitedColor()) + ";}"); css.addRule("a:hover {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkHoverColor()) + ";}"); css.addRule("a:active {color:#" + ColorUtil.toHex(JBUI.CurrentTheme.Link.linkPressedColor()) + ";}"); css.addRule("body {background-color:#" + ColorUtil.toHex(info.warning ? warningBackgroundColor() : errorBackgroundColor()) + ";}"); } if (tipComponent.getCaret() instanceof DefaultCaret) { ((DefaultCaret)tipComponent.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } tipComponent.setCaretPosition(0); tipComponent.setText(text); tipComponent.setBackground(info.warning ? warningBackgroundColor() : errorBackgroundColor()); tipComponent.setOpaque(true); tipComponent.setBorder(getBorder()); if (configurator != null) { configurator.accept(tipComponent); } return JBPopupFactory.getInstance().createComponentPopupBuilder(tipComponent, null). setBorderColor(info.warning ? warningBorderColor() : errorBorderColor()). setCancelOnClickOutside(false). setShowShadow(true); }