Dimension d = jtp_help_center.getPreferredSize(); jtp_help_center.setText(helpText); jtp_help_center.setPreferredSize(d);
@Override public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); assert ESTIMATED_HEIGHT == ImageUtilities.loadImage ("org/netbeans/modules/dialogs/warning.gif").getHeight (null) : "Use only 16px icon."; preferredSize.height = Math.max (ESTIMATED_HEIGHT, preferredSize.height); return preferredSize; } }
public Dimension getPreferredSize(){ Dimension current=super.getPreferredSize(); if (current.height<10) current.height=20; if (current.width<50) current.width=50; return current; }
@Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = 60; return d; }
/** * Overrides the parent's implementation to return a slightly larger * preferred size for circles and rounded rectangles. * * @return Returns the preferreds size for the current view. */ public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); if (shape == SHAPE_CIRCLE) { d.width += d.width / 8; d.height += d.height / 2; } else if (shape == SHAPE_ROUNDED) d.width += d.height / 5; else if (isRichText) { textPane.setSize(ZERO_DIMENSION); return textPane.getPreferredSize(); } else if (valueComponent != null) return valueComponent.getPreferredSize(); return d; }
int prefWidth = Math.max(520, maintainersPane.getPreferredSize().width); int maxHeight = Toolkit.getDefaultToolkit().getScreenSize().height / 2; maxHeight = Math.min(maintainersPane.getPreferredSize().height, maxHeight); maintainersPane.setPreferredSize(new Dimension(prefWidth, maxHeight));
/** * Utility method to paint the rich text content for rich text values. This * implementation simulates rich text vertical alignment by translating the * graphics before painting the textPane. * * @param g * The graphics to paint the rich text content to. */ protected void paintRichText(Graphics g) { textPane.setSize(getSize()); int yoffset = 0; // Computes the vertical offset to match the vertical alignment if (getVerticalAlignment() == CENTER) yoffset = (int) ((getHeight() - textPane.getPreferredSize() .getHeight()) / 2) + 2 * INSET; else if (getVerticalAlignment() == BOTTOM) yoffset = (int) (getHeight() - textPane.getPreferredSize().getHeight() + 3 * INSET); g.translate(0, yoffset); textPane.paint(g); g.translate(0, -yoffset); }
static void showRuleInfoDialog(Component parent, String title, String message, Rule rule, URL matchUrl, ResourceBundle messages, String lang) { int dialogWidth = 320; JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setContentType("text/html"); textPane.setBorder(BorderFactory.createEmptyBorder()); textPane.setOpaque(false); textPane.setBackground(new Color(0, 0, 0, 0)); Tools.addHyperlinkListener(textPane); textPane.setSize(dialogWidth, Short.MAX_VALUE); String messageWithBold = message.replaceAll("<suggestion>", "<b>").replaceAll("</suggestion>", "</b>"); String exampleSentences = getExampleSentences(rule, messages); String url = "http://community.languagetool.org/rule/show/" + encodeUrl(rule) + "?lang=" + lang + "&ref=standalone-gui"; boolean isExternal = rule.getCategory().getLocation() == Category.Location.EXTERNAL; String ruleDetailLink = rule instanceof FalseFriendPatternRule || isExternal ? "" : "<a href='" + url + "'>" + messages.getString("ruleDetailsLink") +"</a>"; textPane.setText("<html>" + messageWithBold + exampleSentences + formatURL(matchUrl) + "<br><br>" + ruleDetailLink + "</html>"); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize( new Dimension(dialogWidth, textPane.getPreferredSize().height)); scrollPane.setBorder(BorderFactory.createEmptyBorder()); String cleanTitle = title.replace("<suggestion>", "'").replace("</suggestion>", "'"); JOptionPane.showMessageDialog(parent, scrollPane, cleanTitle, JOptionPane.INFORMATION_MESSAGE); }
@Override public Dimension getPreferredSize() { if (isPreferredSizeSet()) { return super.getPreferredSize(); } view.setSize(width, 0); Insets insets = getInsets(); Insets margin = getMargin(); float w = view.getPreferredSpan(View.X_AXIS) + insets.left + insets.right + margin.left + margin.right; float h = view.getPreferredSpan(View.Y_AXIS) + insets.bottom + insets.top + margin.bottom + margin.top; return new Dimension((int) Math.ceil(w), (int) Math.ceil(h)); } }
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; width = textWidth + iconWidth + deprecatedWidth;
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; if (textHeight < minTextHeight) { textHeight = minTextHeight;
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; if (textHeight < minTextHeight) { textHeight = minTextHeight;
label.setMargin(new Insets(3, 0, 3, 0)); label.getPreferredSize();
/** * Updates the UI elements in this panel to reflect the attributes in the {@link * #currentCloudLibrary}. */ private void updateUI() { panel.setVisible(true); if (currentCloudLibrary.getIcon() == null) { nameLabel.setIcon(null); } else { nameLabel.setIcon(GoogleCloudCoreIcons.LOADING); loadImageAsync(currentCloudLibrary.getIcon(), nameLabel::setIcon); } nameLabel.setText(currentCloudLibrary.getName()); descriptionTextPane.setText(currentCloudLibrary.getDescription()); descriptionTextPane.setSize( descriptionTextPane.getWidth(), descriptionTextPane.getPreferredSize().height); links.clear(); Optional<String> docsLink = makeLink( GoogleCloudApisMessageBundle.message("cloud.libraries.documentation.link"), currentCloudLibrary.getDocumentation()); links.add(docsLink); linksTextPane.setText(joinLinks(links)); managementWarningTextPane.setText( GoogleCloudApisMessageBundle.message("cloud.apis.management.section.info.text")); }
public Dimension getPreferredSize() { Dimension r =super.getPreferredSize(); Document doc=getDocument(); if(getParent()!=null) r=getParent().getSize(); if(doc instanceof BuAutoStyledDocument) { /*Style fs=*/((BuAutoStyledDocument)doc). getStyle(StyleContext.DEFAULT_STYLE); FontMetrics fm=getFontMetrics(getFont()); int n=doc.getDefaultRootElement().getElementCount(); int c=0; for(int i=0;i<n;i++) { int start=getLineStartOffset(i); int end =getLineEndOffset(i); c=Math.max(c,end-start+1); } // BUG: ignore tabs int w=fm.stringWidth("m")*c; int h=fm.getHeight()*n; Insets insets=getInsets(); r=new Dimension (Math.max(r.width,w+insets.left+insets.right), Math.max(r.height,h+insets.top+insets.bottom)); } return r; }
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; width = textWidth + iconWidth;
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; width = textWidth + iconWidth;
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; if (textHeight < minTextHeight) { textHeight = minTextHeight;
textWidth = textPane.getPreferredSize().width; textHeight = textPane.getPreferredSize().height; if (textHeight < minTextHeight) { textHeight = minTextHeight;
public class DialogTest { public static void main(String[] args) throws Exception { JTextPane jtp = new JTextPane(); Document doc = jtp.getDocument(); for (int i = 0; i < 50; i++) { doc.insertString(doc.getLength(), " Hello Java World ", new SimpleAttributeSet()); if ((3 == i) || (7 == i) || (15 == i)) { doc.insertString(doc.getLength(), " Hello Java World ", new SimpleAttributeSet()); SimpleAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setUnderline(attrs, true); StyleConstants.setForeground(attrs, Color.BLUE); String text = "www.google.com"; URL url = new URL("http://" + text); attrs.addAttribute(HTML.Attribute.HREF, url.toString()); doc.insertString(doc.getLength(), text, attrs); } } //JScrollPane jsp = new JScrollPane(jtp); //jsp.setPreferredSize(new Dimension(480, 150)); //jsp.setBorder(null); jtp.setSize(new Dimension(480, 10)); jtp.setPreferredSize(new Dimension(480, jtp.getPreferredSize().height)); //JOptionPane.showMessageDialog(null, jsp, "Title", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, jtp, "Title", JOptionPane.INFORMATION_MESSAGE); }}