本文整理匯總了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();
}
}