javax.swing.JTextPane.getPreferredSize()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中javax.swing.JTextPane.getPreferredSize()方法的一些代码示例,展示了JTextPane.getPreferredSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.getPreferredSize()方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:getPreferredSize

JTextPane.getPreferredSize介绍

暂无

代码示例

代码示例来源:origin: wiztools/rest-client

  1. Dimension d = jtp_help_center.getPreferredSize();
  2. jtp_help_center.setText(helpText);
  3. jtp_help_center.setPreferredSize(d);

代码示例来源:origin: org.netbeans.api/org-openide-dialogs

  1. @Override
  2. public Dimension getPreferredSize() {
  3. Dimension preferredSize = super.getPreferredSize();
  4. assert ESTIMATED_HEIGHT == ImageUtilities.loadImage ("org/netbeans/modules/dialogs/warning.gif").getHeight (null) : "Use only 16px icon.";
  5. preferredSize.height = Math.max (ESTIMATED_HEIGHT, preferredSize.height);
  6. return preferredSize;
  7. }
  8. }

代码示例来源:origin: net.sf.ingenias/editor

  1. public Dimension getPreferredSize(){
  2. Dimension current=super.getPreferredSize();
  3. if (current.height<10) current.height=20;
  4. if (current.width<50) current.width=50;
  5. return current;
  6. }

代码示例来源:origin: aterai/java-swing-tips

  1. @Override public Dimension getPreferredSize() {
  2. Dimension d = super.getPreferredSize();
  3. d.width = 60;
  4. return d;
  5. }

代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod

  1. /**
  2. * Overrides the parent's implementation to return a slightly larger
  3. * preferred size for circles and rounded rectangles.
  4. *
  5. * @return Returns the preferreds size for the current view.
  6. */
  7. public Dimension getPreferredSize() {
  8. Dimension d = super.getPreferredSize();
  9. if (shape == SHAPE_CIRCLE) {
  10. d.width += d.width / 8;
  11. d.height += d.height / 2;
  12. } else if (shape == SHAPE_ROUNDED)
  13. d.width += d.height / 5;
  14. else if (isRichText) {
  15. textPane.setSize(ZERO_DIMENSION);
  16. return textPane.getPreferredSize();
  17. } else if (valueComponent != null)
  18. return valueComponent.getPreferredSize();
  19. return d;
  20. }

代码示例来源:origin: org.languagetool/languagetool-gui-commons

  1. int prefWidth = Math.max(520, maintainersPane.getPreferredSize().width);
  2. int maxHeight = Toolkit.getDefaultToolkit().getScreenSize().height / 2;
  3. maxHeight = Math.min(maintainersPane.getPreferredSize().height, maxHeight);
  4. maintainersPane.setPreferredSize(new Dimension(prefWidth, maxHeight));

代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod

  1. /**
  2. * Utility method to paint the rich text content for rich text values. This
  3. * implementation simulates rich text vertical alignment by translating the
  4. * graphics before painting the textPane.
  5. *
  6. * @param g
  7. * The graphics to paint the rich text content to.
  8. */
  9. protected void paintRichText(Graphics g) {
  10. textPane.setSize(getSize());
  11. int yoffset = 0;
  12. // Computes the vertical offset to match the vertical alignment
  13. if (getVerticalAlignment() == CENTER)
  14. yoffset = (int) ((getHeight() - textPane.getPreferredSize()
  15. .getHeight()) / 2)
  16. + 2 * INSET;
  17. else if (getVerticalAlignment() == BOTTOM)
  18. yoffset = (int) (getHeight()
  19. - textPane.getPreferredSize().getHeight() + 3 * INSET);
  20. g.translate(0, yoffset);
  21. textPane.paint(g);
  22. g.translate(0, -yoffset);
  23. }

代码示例来源:origin: org.languagetool/languagetool-gui-commons

  1. static void showRuleInfoDialog(Component parent, String title, String message, Rule rule, URL matchUrl, ResourceBundle messages, String lang) {
  2. int dialogWidth = 320;
  3. JTextPane textPane = new JTextPane();
  4. textPane.setEditable(false);
  5. textPane.setContentType("text/html");
  6. textPane.setBorder(BorderFactory.createEmptyBorder());
  7. textPane.setOpaque(false);
  8. textPane.setBackground(new Color(0, 0, 0, 0));
  9. Tools.addHyperlinkListener(textPane);
  10. textPane.setSize(dialogWidth, Short.MAX_VALUE);
  11. String messageWithBold = message.replaceAll("<suggestion>", "<b>").replaceAll("</suggestion>", "</b>");
  12. String exampleSentences = getExampleSentences(rule, messages);
  13. String url = "http://community.languagetool.org/rule/show/" + encodeUrl(rule)
  14. + "?lang=" + lang + "&amp;ref=standalone-gui";
  15. boolean isExternal = rule.getCategory().getLocation() == Category.Location.EXTERNAL;
  16. String ruleDetailLink = rule instanceof FalseFriendPatternRule || isExternal ?
  17. "" : "<a href='" + url + "'>" + messages.getString("ruleDetailsLink") +"</a>";
  18. textPane.setText("<html>"
  19. + messageWithBold + exampleSentences + formatURL(matchUrl)
  20. + "<br><br>"
  21. + ruleDetailLink
  22. + "</html>");
  23. JScrollPane scrollPane = new JScrollPane(textPane);
  24. scrollPane.setPreferredSize(
  25. new Dimension(dialogWidth, textPane.getPreferredSize().height));
  26. scrollPane.setBorder(BorderFactory.createEmptyBorder());
  27. String cleanTitle = title.replace("<suggestion>", "'").replace("</suggestion>", "'");
  28. JOptionPane.showMessageDialog(parent, scrollPane, cleanTitle,
  29. JOptionPane.INFORMATION_MESSAGE);
  30. }

代码示例来源:origin: org.japura/japura-gui

  1. @Override
  2. public Dimension getPreferredSize() {
  3. if (isPreferredSizeSet()) {
  4. return super.getPreferredSize();
  5. }
  6. view.setSize(width, 0);
  7. Insets insets = getInsets();
  8. Insets margin = getMargin();
  9. float w =
  10. view.getPreferredSpan(View.X_AXIS) + insets.left + insets.right
  11. + margin.left + margin.right;
  12. float h =
  13. view.getPreferredSpan(View.Y_AXIS) + insets.bottom + insets.top
  14. + margin.bottom + margin.top;
  15. return new Dimension((int) Math.ceil(w), (int) Math.ceil(h));
  16. }
  17. }

代码示例来源:origin: org.protege/protege-editor-owl

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. width = textWidth + iconWidth + deprecatedWidth;

代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. if (textHeight < minTextHeight) {
  4. textHeight = minTextHeight;

代码示例来源:origin: org.protege/protege-editor-owl

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. if (textHeight < minTextHeight) {
  4. textHeight = minTextHeight;

代码示例来源:origin: org.codehaus.izpack/izpack-panel

  1. label.setMargin(new Insets(3, 0, 3, 0));
  2. label.getPreferredSize();

代码示例来源:origin: GoogleCloudPlatform/google-cloud-intellij

  1. /**
  2. * Updates the UI elements in this panel to reflect the attributes in the {@link
  3. * #currentCloudLibrary}.
  4. */
  5. private void updateUI() {
  6. panel.setVisible(true);
  7. if (currentCloudLibrary.getIcon() == null) {
  8. nameLabel.setIcon(null);
  9. } else {
  10. nameLabel.setIcon(GoogleCloudCoreIcons.LOADING);
  11. loadImageAsync(currentCloudLibrary.getIcon(), nameLabel::setIcon);
  12. }
  13. nameLabel.setText(currentCloudLibrary.getName());
  14. descriptionTextPane.setText(currentCloudLibrary.getDescription());
  15. descriptionTextPane.setSize(
  16. descriptionTextPane.getWidth(), descriptionTextPane.getPreferredSize().height);
  17. links.clear();
  18. Optional<String> docsLink =
  19. makeLink(
  20. GoogleCloudApisMessageBundle.message("cloud.libraries.documentation.link"),
  21. currentCloudLibrary.getDocumentation());
  22. links.add(docsLink);
  23. linksTextPane.setText(joinLinks(links));
  24. managementWarningTextPane.setText(
  25. GoogleCloudApisMessageBundle.message("cloud.apis.management.section.info.text"));
  26. }

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

  1. public Dimension getPreferredSize()
  2. {
  3. Dimension r =super.getPreferredSize();
  4. Document doc=getDocument();
  5. if(getParent()!=null)
  6. r=getParent().getSize();
  7. if(doc instanceof BuAutoStyledDocument)
  8. {
  9. /*Style fs=*/((BuAutoStyledDocument)doc).
  10. getStyle(StyleContext.DEFAULT_STYLE);
  11. FontMetrics fm=getFontMetrics(getFont());
  12. int n=doc.getDefaultRootElement().getElementCount();
  13. int c=0;
  14. for(int i=0;i<n;i++)
  15. {
  16. int start=getLineStartOffset(i);
  17. int end =getLineEndOffset(i);
  18. c=Math.max(c,end-start+1);
  19. }
  20. // BUG: ignore tabs
  21. int w=fm.stringWidth("m")*c;
  22. int h=fm.getHeight()*n;
  23. Insets insets=getInsets();
  24. r=new Dimension
  25. (Math.max(r.width,w+insets.left+insets.right),
  26. Math.max(r.height,h+insets.top+insets.bottom));
  27. }
  28. return r;
  29. }

代码示例来源:origin: protegeproject/protege

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. width = textWidth + iconWidth;

代码示例来源:origin: edu.stanford.protege/protege-editor-owl

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. width = textWidth + iconWidth;

代码示例来源:origin: protegeproject/protege

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. if (textHeight < minTextHeight) {
  4. textHeight = minTextHeight;

代码示例来源:origin: edu.stanford.protege/protege-editor-owl

  1. textWidth = textPane.getPreferredSize().width;
  2. textHeight = textPane.getPreferredSize().height;
  3. if (textHeight < minTextHeight) {
  4. textHeight = minTextHeight;

代码示例来源:origin: stackoverflow.com

  1. public class DialogTest {
  2. public static void main(String[] args) throws Exception {
  3. JTextPane jtp = new JTextPane();
  4. Document doc = jtp.getDocument();
  5. for (int i = 0; i < 50; i++) {
  6. doc.insertString(doc.getLength(), " Hello Java World ", new SimpleAttributeSet());
  7. if ((3 == i) || (7 == i) || (15 == i)) {
  8. doc.insertString(doc.getLength(), " Hello Java World ", new SimpleAttributeSet());
  9. SimpleAttributeSet attrs = new SimpleAttributeSet();
  10. StyleConstants.setUnderline(attrs, true);
  11. StyleConstants.setForeground(attrs, Color.BLUE);
  12. String text = "www.google.com";
  13. URL url = new URL("http://" + text);
  14. attrs.addAttribute(HTML.Attribute.HREF, url.toString());
  15. doc.insertString(doc.getLength(), text, attrs);
  16. }
  17. }
  18. //JScrollPane jsp = new JScrollPane(jtp);
  19. //jsp.setPreferredSize(new Dimension(480, 150));
  20. //jsp.setBorder(null);
  21. jtp.setSize(new Dimension(480, 10));
  22. jtp.setPreferredSize(new Dimension(480, jtp.getPreferredSize().height));
  23. //JOptionPane.showMessageDialog(null, jsp, "Title", JOptionPane.INFORMATION_MESSAGE);
  24. JOptionPane.showMessageDialog(null, jtp, "Title", JOptionPane.INFORMATION_MESSAGE);
  25. }}

相关文章

JTextPane类方法