本文整理汇总了Java中java.awt.LayoutManager.preferredLayoutSize方法的典型用法代码示例。如果您正苦于以下问题:Java LayoutManager.preferredLayoutSize方法的具体用法?Java LayoutManager.preferredLayoutSize怎么用?Java LayoutManager.preferredLayoutSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.LayoutManager
的用法示例。
在下文中一共展示了LayoutManager.preferredLayoutSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreferredSize
import java.awt.LayoutManager; //导入方法依赖的package包/类
public Dimension getPreferredSize(JComponent c) {
LayoutManager layout = c.getLayout();
Dimension d = layout.preferredLayoutSize(c);
String title = ((JPopupMenu)c).getLabel();
if (titleFont == null) {
UIDefaults table = UIManager.getLookAndFeelDefaults();
titleFont = table.getFont("PopupMenu.font");
}
FontMetrics fm = c.getFontMetrics(titleFont);
int stringWidth = 0;
if (title!=null) {
stringWidth += SwingUtilities2.stringWidth(c, fm, title);
}
if (d.width < stringWidth) {
d.width = stringWidth + 8;
Insets i = c.getInsets();
if (i!=null) {
d.width += i.left + i.right;
}
if (border != null) {
i = border.getBorderInsets(c);
d.width += i.left + i.right;
}
return d;
}
return null;
}
示例2: getPreferredSize
import java.awt.LayoutManager; //导入方法依赖的package包/类
/**
* This method returns the preferred size of the given JComponent.
*
* @param x The JComponent to find a preferred size for.
*
* @return The preferred size.
*/
public Dimension getPreferredSize(JComponent x)
{
Dimension pref = null;
LayoutManager layout = frame.getLayout();
if (frame == x && layout != null)
pref = layout.preferredLayoutSize(frame);
else
pref = new Dimension(100, 100);
return pref;
}