本文整理了Java中javax.swing.JTextPane.getPreferredSize()
方法的一些代码示例,展示了JTextPane.getPreferredSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextPane.getPreferredSize()
方法的具体详情如下:
包路径:javax.swing.JTextPane
类名称:JTextPane
方法名:getPreferredSize
暂无
代码示例来源:origin: wiztools/rest-client
Dimension d = jtp_help_center.getPreferredSize();
jtp_help_center.setText(helpText);
jtp_help_center.setPreferredSize(d);
代码示例来源:origin: org.netbeans.api/org-openide-dialogs
@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;
}
}
代码示例来源:origin: net.sf.ingenias/editor
public Dimension getPreferredSize(){
Dimension current=super.getPreferredSize();
if (current.height<10) current.height=20;
if (current.width<50) current.width=50;
return current;
}
代码示例来源:origin: aterai/java-swing-tips
@Override public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.width = 60;
return d;
}
代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod
/**
* 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;
}
代码示例来源:origin: org.languagetool/languagetool-gui-commons
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));
代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod
/**
* 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);
}
代码示例来源:origin: org.languagetool/languagetool-gui-commons
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);
}
代码示例来源:origin: org.japura/japura-gui
@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));
}
}
代码示例来源:origin: org.protege/protege-editor-owl
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
width = textWidth + iconWidth + deprecatedWidth;
代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
if (textHeight < minTextHeight) {
textHeight = minTextHeight;
代码示例来源:origin: org.protege/protege-editor-owl
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
if (textHeight < minTextHeight) {
textHeight = minTextHeight;
代码示例来源:origin: org.codehaus.izpack/izpack-panel
label.setMargin(new Insets(3, 0, 3, 0));
label.getPreferredSize();
代码示例来源:origin: GoogleCloudPlatform/google-cloud-intellij
/**
* 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"));
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu
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;
}
代码示例来源:origin: protegeproject/protege
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
width = textWidth + iconWidth;
代码示例来源:origin: edu.stanford.protege/protege-editor-owl
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
width = textWidth + iconWidth;
代码示例来源:origin: protegeproject/protege
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
if (textHeight < minTextHeight) {
textHeight = minTextHeight;
代码示例来源:origin: edu.stanford.protege/protege-editor-owl
textWidth = textPane.getPreferredSize().width;
textHeight = textPane.getPreferredSize().height;
if (textHeight < minTextHeight) {
textHeight = minTextHeight;
代码示例来源:origin: stackoverflow.com
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);
}}
内容来源于网络,如有侵权,请联系作者删除!