Java Code Examples for java.awt.Container#getPreferredSize()

The following examples show how to use java.awt.Container#getPreferredSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KTrussControllerTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: KTrussControllerTopComponent.java    From constellation with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: StatisticsDialog.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
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);
	}
}
 
Example 4
Source File: AbstractViewTabDisplayerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Dimension preferredLayoutSize( Container parent ) {
    return parent.getPreferredSize();
}
 
Example 5
Source File: AbstractViewTabDisplayerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Dimension minimumLayoutSize( Container parent ) {
    return parent.getPreferredSize();
}
 
Example 6
Source File: PageAssembler.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: SimpleGridLayout.java    From swift-k with Apache License 2.0 4 votes vote down vote up
public Dimension preferredLayoutSize(Container container) {
	if (container instanceof GridContainer) {
		return container.getPreferredSize();
	}
	return container.getSize();
}
 
Example 8
Source File: GradientEditorLayout.java    From microba with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
	return parent.getPreferredSize();
}