下面列出了javax.swing.JComponent#getMaximumSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
int getMaximumHeight() {
Row row = rows.get(rowIndex);
int maxHeight = 0;
for (int a = 0; a < row.componentListUnwrapped.size(); a++) {
JComponent jc = row.componentListUnwrapped.get(a);
if (jc != null && theoreticalBoundsTable.get(jc) != null) {
int width = theoreticalBoundsTable.get(jc).width;
Dimension d = getMaximumSize(jc, width);
if (d == null)
d = jc.getMaximumSize();
if (d != null)
maxHeight = Math.max(maxHeight, d.height);
}
}
return maxHeight;
}
private int getMaximumExtraHeight(Row row, int[] columnWidths) {
int maxExtraHeight = 0;
for (int a = 0; a < row.columns.length; a++) {
if (row.columns[a] != null) {
int columnWidth = columnWidths[a];
for (int b = 0; b < row.columns[a].components.length; b++) {
JComponent jc = row.columns[a].components[b];
ComponentConstraints c = row.columns[a].constraints[b];
if (jc != null
&& jc.isVisible()
&& c.verticalPriority == profile.maxVisiblePriority) {
Dimension maxSize = getMaximumSize(jc, columnWidth);
if (maxSize == null)
maxSize = jc.getMaximumSize();
Dimension preferredSize = getPreferredSize(jc);
maxExtraHeight = Math.max(maxExtraHeight,
maxSize.height - preferredSize.height);
}
}
}
}
return maxExtraHeight;
}
final Dimension getPreferredSize() {
JComponent comp = getContentComponent();
if (comp == null)
return new Dimension(0, 0);
int screenWidth = Utilities.getUsableScreenBounds().width;
Dimension maxSize = new Dimension((int) (screenWidth * MAX_COMPL_COVERAGE),
comp.getMaximumSize().height); //set maximum part of screen covered
setMaxSize(comp, maxSize);
return comp.getPreferredSize();
}
final Dimension getPreferredSize() {
JComponent comp = getContentComponent();
if (comp == null)
return new Dimension(0, 0);
int screenWidth = Utilities.getUsableScreenBounds().width;
Dimension maxSize = new Dimension((int) (screenWidth * MAX_COMPL_COVERAGE),
comp.getMaximumSize().height); //set maximum part of screen covered
setMaxSize(comp, maxSize);
return comp.getPreferredSize();
}
final Dimension getPreferredSize() {
JComponent comp = getContentComponent();
if (comp == null) {
return new Dimension(0, 0);
}
int screenWidth = Utilities.getUsableScreenBounds().width;
Dimension maxSize = new Dimension((int) (screenWidth * MAX_COMPL_COVERAGE),
comp.getMaximumSize().height); //set maximum part of screen covered
setMaxSize(comp, maxSize);
return comp.getPreferredSize();
}
/**
* Returns the maximum amount of space the layout can use.
*
* @param target the target
* @return a Dimension object containing the layout's maximum size
*/
public Dimension maximumLayoutSize(Container target)
{
Dimension cpd, mbd, tpd;
int cpWidth = Integer.MAX_VALUE;
int cpHeight = Integer.MAX_VALUE;
int mbWidth = Integer.MAX_VALUE;
int mbHeight = Integer.MAX_VALUE;
int tpWidth = Integer.MAX_VALUE;
int tpHeight = Integer.MAX_VALUE;
Insets i = target.getInsets();
JRootPane root = (JRootPane) target;
if(root.getContentPane() != null)
{
cpd = root.getContentPane().getMaximumSize();
if (cpd != null)
{
cpWidth = cpd.width;
cpHeight = cpd.height;
}
}
if(root.getMenuBar() != null)
{
mbd = root.getMenuBar().getMaximumSize();
if (mbd != null)
{
mbWidth = mbd.width;
mbHeight = mbd.height;
}
}
if (root.getWindowDecorationStyle() != JRootPane.NONE &&
(root.getUI() instanceof BERootPaneUI))
{
JComponent titlePane = ((BERootPaneUI)root.getUI()).
getTitlePane();
if (titlePane != null)
{
tpd = titlePane.getMaximumSize();
if (tpd != null)
{
tpWidth = tpd.width;
tpHeight = tpd.height;
}
}
}
int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
// Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
// Only will happen if sums to more than 2 billion units. Not likely.
if (maxHeight != Integer.MAX_VALUE)
{
maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
}
int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
// Similar overflow comment as above
if (maxWidth != Integer.MAX_VALUE)
{
maxWidth += i.left + i.right;
}
return new Dimension(maxWidth, maxHeight);
}
/**
* Returns the maximum amount of space the layout can use.
*
* @param target the Container for which this layout manager is being
* used
*
* @return a Dimension object containing the layout's maximum size
*/
public Dimension maximumLayoutSize(Container target) {
Dimension cpd;
Dimension mbd;
Dimension tpd;
int cpWidth = Integer.MAX_VALUE;
int cpHeight = Integer.MAX_VALUE;
int mbWidth = Integer.MAX_VALUE;
int mbHeight = Integer.MAX_VALUE;
int tpWidth = Integer.MAX_VALUE;
int tpHeight = Integer.MAX_VALUE;
Insets i = target.getInsets();
JRootPane root = (JRootPane) target;
if (root.getContentPane() != null) {
cpd = root.getContentPane().getMaximumSize();
if (cpd != null) {
cpWidth = cpd.width;
cpHeight = cpd.height;
}
}
if (root.getJMenuBar() != null) {
mbd = root.getJMenuBar().getMaximumSize();
if (mbd != null) {
mbWidth = mbd.width;
mbHeight = mbd.height;
}
}
if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
JComponent titlePane = ((SeaGlassRootPaneUI) root.getUI()).getTitlePane();
if (titlePane != null) {
tpd = titlePane.getMaximumSize();
if (tpd != null) {
tpWidth = tpd.width;
tpHeight = tpd.height;
}
}
}
int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
// Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
// Only will happen if sums to more than 2 billion units. Not likely.
if (maxHeight != Integer.MAX_VALUE) {
maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
}
int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
// Similar overflow comment as above
if (maxWidth != Integer.MAX_VALUE) {
maxWidth += i.left + i.right;
}
return new Dimension(maxWidth, maxHeight);
}
static JComponent fixedHeight(JComponent component) {
Dimension dim = component.getMaximumSize();
dim.height = component.getPreferredSize().height;
component.setMaximumSize(dim);
return component;
}
static JComponent fixedHeight(JComponent component) {
Dimension dim = component.getMaximumSize();
dim.height = component.getPreferredSize().height;
component.setMaximumSize(dim);
return component;
}
public void setMaxWidth( JComponent jc, int width ) {
Dimension max = jc.getMaximumSize();
max.width = width;
jc.setMaximumSize( max );
}
/**
* Sets the maximum height of a JComponent to its preferred height, thereby
* preventing it from being expanded. The component itself is returned, to allow
* shortcuts such as: xyz.add(JUtils.fixHeight(component)).
*
* @param c the component to be height-fixed
* @return the component
*/
public static JComponent fixHeight(JComponent c) {
Dimension max = c.getMaximumSize();
max.height = c.getPreferredSize().height;
c.setMaximumSize(max);
return c;
}
/**
* Sets the maximum width of a JComponent to its preferred width, thereby
* preventing it from being expanded. The component itself is returned, to allow
* shortcuts such as: xyz.add(JUtils.fixWidth(component)).
*
* @param c the component to be width-fixed
* @return the component
*/
public static JComponent fixWidth(JComponent c) {
Dimension max = c.getMaximumSize();
max.width = c.getPreferredSize().width;
c.setMaximumSize(max);
return c;
}