本文整理汇总了Java中javax.swing.JEditorPane.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.setSize方法的具体用法?Java JEditorPane.setSize怎么用?Java JEditorPane.setSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.setSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentHeight
import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
* 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) {
if (comment == null) {
throw new IllegalArgumentException("comment must not be null!");
}
JEditorPane dummyEditorPane = new JEditorPane("text/html", "");
dummyEditorPane.setText(comment);
dummyEditorPane.setBorder(null);
dummyEditorPane.setSize(width, Short.MAX_VALUE);
// 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();
}
}