下面列出了java.awt.Container#getPreferredSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void hideNestedTrussesPanel() {
if (!nestedPanelIsVisible) {
return;
}
Dimension d;
int sizeDifference = nestedTrussesHeight - nestedTrussButton.getHeight();
nestedTrussPane.setSize(200, 0);
nestedTrussPane.setMinimumSize(new Dimension(nestedTrussPane.getMinimumSize().width, 0));
nestedTrussPane.setPreferredSize(new Dimension(200, 0));
nestedTrussButton.setText("V");
// resize this top component
setSize(getWidth(), getHeight() - sizeDifference);
d = getPreferredSize();
d.height -= sizeDifference;
setPreferredSize(d);
d = getMinimumSize();
d.height -= sizeDifference;
setMinimumSize(d);
// The grandparent of this TopComponent is the netbeans level JPanel we need to resize when in 'sliding/docked+minimised' mode. The parent of this TopComponent represents a tab, which we are not
// interested in since it will be resized along with the JPanel
Container grandParentContainer = getParent().getParent();
grandParentContainer.setSize(grandParentContainer.getWidth(), grandParentContainer.getHeight() - sizeDifference);
d = grandParentContainer.getPreferredSize();
d.height -= sizeDifference;
grandParentContainer.setPreferredSize(d);
nestedPanelIsVisible = false;
}
private void showNestedTrussesPanel() {
if (nestedPanelIsVisible) {
return;
}
Dimension d;
int sizeDifference = nestedTrussesHeight - nestedTrussButton.getHeight();
nestedTrussPane.setSize(200, nestedTrussesHeight);
nestedTrussPane.setMinimumSize(new Dimension(nestedTrussPane.getMinimumSize().width, nestedTrussesHeight));
nestedTrussPane.setPreferredSize(new Dimension(200, nestedTrussesHeight));
nestedTrussButton.setText("^");
//resize this top component
setSize(getWidth(), getHeight() + sizeDifference);
d = getPreferredSize();
d.height += sizeDifference;
setPreferredSize(d);
d = getMinimumSize();
d.height += sizeDifference;
setMinimumSize(d);
// resize the grandparent of this top component
Container grandParentContainer = getParent().getParent();
grandParentContainer.setSize(grandParentContainer.getWidth(), grandParentContainer.getHeight() + sizeDifference);
d = grandParentContainer.getPreferredSize();
d.height += sizeDifference;
grandParentContainer.setPreferredSize(d);
nestedPanelIsVisible = true;
}
private StatisticsDialog(JFrame parent, String circuitName, StatisticsTableModel model) {
super(parent, true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle(Strings.get("statsDialogTitle", circuitName));
JTable table = new StatisticsTable();
TableSorter mySorter = new TableSorter(model, table.getTableHeader());
Comparator<String> comp = new CompareString("", Strings.get("statsTotalWithout"),
Strings.get("statsTotalWith"));
mySorter.setColumnComparator(String.class, comp);
table.setModel(mySorter);
JScrollPane tablePane = new JScrollPane(table);
JButton button = new JButton(Strings.get("statsCloseButton"));
button.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.add(button);
Container contents = this.getContentPane();
contents.setLayout(new BorderLayout());
contents.add(tablePane, BorderLayout.CENTER);
contents.add(buttonPanel, BorderLayout.PAGE_END);
this.pack();
this.setLocationRelativeTo(null);
Dimension pref = contents.getPreferredSize();
if (pref.width > 750 || pref.height > 550) {
if (pref.width > 750)
pref.width = 750;
if (pref.height > 550)
pref.height = 550;
this.setSize(pref);
}
}
@Override
public Dimension preferredLayoutSize( Container parent ) {
return parent.getPreferredSize();
}
@Override
public Dimension minimumLayoutSize( Container parent ) {
return parent.getPreferredSize();
}
/**
* Add a panel to the content of the page.
*
* @param panel The panel to add.
* @param leftInfo Outline info for the left outline.
* @param rightInfo Outline info for the right outline.
* @return {@code true} if the panel was too big to fit on a single page.
*/
public boolean addToContent(Container panel, OutlineInfo leftInfo, OutlineInfo rightInfo) {
boolean isOutline = panel instanceof SingleOutlinePanel || panel instanceof DoubleOutlinePanel;
int height = 0;
int minLeft = 0;
int minRight = 0;
if (mContent.getComponentCount() > 0) {
mRemaining -= Scale.get(mContent).scale(GAP);
}
if (isOutline) {
minLeft = leftInfo.getMinimumHeight();
if (panel instanceof SingleOutlinePanel) {
height += minLeft;
} else {
minRight = rightInfo.getMinimumHeight();
height += Math.max(minLeft, minRight);
}
} else {
height += panel.getPreferredSize().height;
}
if (mRemaining < height) {
addPageInternal();
}
mContent.add(panel);
if (isOutline) {
int savedRemaining = mRemaining;
boolean hasMore;
if (panel instanceof SingleOutlinePanel) {
int startIndex = leftInfo.getRowIndex() + 1;
int amt = leftInfo.determineHeightForOutline(mRemaining);
((SingleOutlinePanel) panel).setOutlineRowRange(startIndex, leftInfo.getRowIndex());
if (amt < minLeft) {
amt = minLeft;
}
mRemaining = savedRemaining - amt;
hasMore = leftInfo.hasMore();
} else {
DoubleOutlinePanel panel2 = (DoubleOutlinePanel) panel;
int leftStart = leftInfo.getRowIndex() + 1;
int leftHeight = leftInfo.determineHeightForOutline(mRemaining);
int rightStart = rightInfo.getRowIndex() + 1;
int rightHeight = rightInfo.determineHeightForOutline(mRemaining);
panel2.setOutlineRowRange(false, leftStart, leftInfo.getRowIndex());
panel2.setOutlineRowRange(true, rightStart, rightInfo.getRowIndex());
if (leftHeight < minLeft) {
leftHeight = minLeft;
}
if (rightHeight < minRight) {
rightHeight = minRight;
}
mRemaining = leftHeight < rightHeight ? savedRemaining - rightHeight : savedRemaining - leftHeight;
hasMore = leftInfo.hasMore() || rightInfo.hasMore();
}
if (hasMore) {
addPageInternal();
return true;
}
return false;
}
if (mRemaining >= height) {
mRemaining -= height;
return false;
}
addPageInternal();
return true;
}
public Dimension preferredLayoutSize(Container container) {
if (container instanceof GridContainer) {
return container.getPreferredSize();
}
return container.getSize();
}
public Dimension preferredLayoutSize(Container parent) {
return parent.getPreferredSize();
}