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

The following examples show how to use java.awt.Container#setPreferredSize() . 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: ClusterTest.java    From moleculer-java with MIT License 6 votes vote down vote up
public ClusterTest() {
	setTitle("Simulation of " + NODES + " nodes");
	setResizable(false);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	Container root = getContentPane();
	root.setLayout(new BorderLayout());
	Dimension size = new Dimension(NODES * PIXEL_SIZE, NODES * PIXEL_SIZE);
	image = new ImagePanel(size);
	root.add(image, BorderLayout.CENTER);
	root.setSize(size);
	root.setPreferredSize(size);
	pack();
	setVisible(true);
	Thread t = new Thread(this);
	t.start();
}
 
Example 2
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 3
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;
}