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