本文整理汇总了Java中javax.swing.JScrollPane.getPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:Java JScrollPane.getPreferredSize方法的具体用法?Java JScrollPane.getPreferredSize怎么用?Java JScrollPane.getPreferredSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JScrollPane
的用法示例。
在下文中一共展示了JScrollPane.getPreferredSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showDialog
import javax.swing.JScrollPane; //导入方法依赖的package包/类
/** Shows the content of this table as a dialog. */
public void showDialog(Component parent) {
JScrollPane scrollPane = new JScrollPane(this);
Dimension size = scrollPane.getPreferredSize();
size.height = getPreferredSize().height;
scrollPane.getViewport().setPreferredSize(size);
JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE);
JDialog dialog = optionPane.createDialog(parent, "External libraries used in GROOVE");
dialog.setVisible(true);
}
示例2: adjustScrollPaneSize
import javax.swing.JScrollPane; //导入方法依赖的package包/类
private static void adjustScrollPaneSize(JScrollPane sp, JEditorPane editorPane) {
int height;
//logger.fine("createSingleLineEditor(): editorPane's margin = "+editorPane.getMargin());
//logger.fine("createSingleLineEditor(): editorPane's insets = "+editorPane.getInsets());
Dimension prefSize = sp.getPreferredSize();
Insets borderInsets = sp.getBorder().getBorderInsets(sp);//sp.getInsets();
int vBorder = borderInsets.bottom + borderInsets.top;
EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane);
if (logger.isLoggable(Level.FINE)) {
logger.fine("createSingleLineEditor(): editor UI = "+eui);
if (eui != null) {
logger.fine("createSingleLineEditor(): editor UI's line height = "+eui.getLineHeight());
logger.fine("createSingleLineEditor(): editor UI's line ascent = "+eui.getLineAscent());
}
}
if (eui != null) {
height = eui.getLineHeight();
if (height < eui.getLineAscent()) {
height = (eui.getLineAscent()*4)/3; // Hack for the case when line height = 1
}
} else {
java.awt.Font font = editorPane.getFont();
java.awt.FontMetrics fontMetrics = editorPane.getFontMetrics(font);
height = fontMetrics.getHeight();
//logger.fine("createSingleLineEditor(): editor's font = "+font+" with metrics = "+fontMetrics+", leading = "+fontMetrics.getLeading());
//logger.fine("createSingleLineEditor(): font's height = "+height);
}
height += vBorder + getLFHeightAdjustment();
//height += 2; // 2 for border
if (logger.isLoggable(Level.FINE)) {
logger.fine("createSingleLineEditor(): border vertical insets = "+borderInsets.bottom+" + "+borderInsets.top);
logger.fine("createSingleLineEditor(): computed height = "+height+", prefSize = "+prefSize);
}
if (prefSize.height < height) {
prefSize.height = height;
sp.setPreferredSize(prefSize);
sp.setMinimumSize(prefSize);
sp.setMaximumSize(prefSize);
java.awt.Container c = sp.getParent();
logger.fine("createSingleLineEditor(): setting a new height of ScrollPane = "+height);
if (c instanceof JComponent) {
((JComponent) c).revalidate();
}
}
}