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

The following examples show how to use java.awt.Component#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: ListLayout.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
    Dimension dim = preferredLayoutSize(parent);
    Insets ins = parent.getInsets();
    int top = ins.top;
    boolean first = true;
    for (Component c : parent.getComponents()) {
        if (!c.isVisible()) {
            continue;
        }
        if (!first) {
            top += border;
        }
        Dimension pref = c.getPreferredSize();
        c.setPreferredSize(new Dimension(dim.width, pref.height));
        c.setMinimumSize(new Dimension(dim.width, pref.height));
        c.setBounds(0, top, dim.width, pref.height);
        top += pref.height;
        first = false;
    }

}
 
Example 2
Source File: XMBeanAttributes.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 3
Source File: XMBeanNotifications.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
UserDataCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 200) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
    }
}
 
Example 4
Source File: XMBeanAttributes.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 5
Source File: XMBeanNotifications.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
UserDataCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 200) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
    }
}
 
Example 6
Source File: XMBeanNotifications.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
UserDataCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 200) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
    }
}
 
Example 7
Source File: XMBeanAttributes.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 8
Source File: XMBeanAttributes.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 9
Source File: XMBeanNotifications.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
UserDataCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 200) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
    }
}
 
Example 10
Source File: XMBeanAttributes.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 11
Source File: XMBeanNotifications.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
UserDataCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 200) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
    }
}
 
Example 12
Source File: AddPlacePrompt.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addInput(JPanel p, Component c, int inputSize, GridBagConstraints gbc) {
   gbc.gridx = 1;
   gbc.fill = inputSize > 0 ? GridBagConstraints.NONE : GridBagConstraints.HORIZONTAL;
   gbc.anchor = GridBagConstraints.NORTHWEST;
   gbc.weightx = inputSize > 0 ? 0 : 1;
   if (inputSize > 0) {
      c.setPreferredSize(new Dimension(inputSize, c.getPreferredSize().height));
      c.setMinimumSize(c.getPreferredSize());
   }
   p.add(c, gbc.clone());
}
 
Example 13
Source File: BillingInformationPrompt.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addInput(JPanel p, Component c, int inputSize, GridBagConstraints gbc) {
   gbc.gridx = 1;
   gbc.fill = inputSize > 0 ? GridBagConstraints.NONE : GridBagConstraints.HORIZONTAL;
   gbc.anchor = GridBagConstraints.NORTHWEST;
   gbc.weightx = inputSize > 0 ? 0 : 1;
   if (inputSize > 0) {
      c.setPreferredSize(new Dimension(inputSize, c.getPreferredSize().height));
      c.setMinimumSize(c.getPreferredSize());
   }
   p.add(c, gbc.clone());
}
 
Example 14
Source File: DeletePrompt.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addInput(JPanel p, Component c, int inputSize, GridBagConstraints gbc) {
   gbc.gridx = 1;
   gbc.fill = inputSize > 0 ? GridBagConstraints.NONE : GridBagConstraints.HORIZONTAL;
   gbc.anchor = GridBagConstraints.NORTHWEST;
   gbc.weightx = inputSize > 0 ? 0 : 1;
   if (inputSize > 0) {
      c.setPreferredSize(new Dimension(inputSize, c.getPreferredSize().height));
      c.setMinimumSize(c.getPreferredSize());
   }
   p.add(c, gbc.clone());
}
 
Example 15
Source File: XMBeanAttributes.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 16
Source File: XMBeanAttributes.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 17
Source File: HeapFragmentWalkerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void unifyComponentsSize(Component c1, Component c2) {
    Dimension preferredSize = new Dimension(Math.max(c1.getPreferredSize().width, c2.getPreferredSize().width),
                                            Math.max(c1.getPreferredSize().height, c2.getPreferredSize().height));
    c1.setPreferredSize(preferredSize);
    c2.setPreferredSize(preferredSize);
}
 
Example 18
Source File: UIHelper.java    From java-photoslibrary with Apache License 2.0 4 votes vote down vote up
public static void setFixedSize(Component component, Dimension dimension) {
  component.setSize(dimension);
  component.setPreferredSize(dimension);
  component.setMaximumSize(dimension);
  component.setMinimumSize(dimension);
}
 
Example 19
Source File: ChangeWindowResizabiltyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    for(int i = 0; i < 10; i++) {
        Dialog dialog = new Dialog((Frame) null);
        dialog.setLocation(100, 100);
        Component panel = new Panel();
        panel.setPreferredSize(new Dimension(200, 100));
        dialog.add(panel);
        dialog.pack();
        dialog.setVisible(true);
        robot.waitForIdle();
        robot.delay(200);

        Point frameLoc = dialog.getLocationOnScreen();
        Point contentLoc = panel.getLocationOnScreen();

        System.out.println("Decor location " + frameLoc);
        System.out.println("Content location " + contentLoc);

        dialog.setResizable(false);
        robot.waitForIdle();
        robot.delay(200);

        Point l = dialog.getLocationOnScreen();
        if (!l.equals(frameLoc)) {
            dialog.dispose();
            throw new RuntimeException("Decorated frame location moved " +
                    "after setResizable(false)" + l);
        }

        l = panel.getLocationOnScreen();
        if (!l.equals(contentLoc)) {
            dialog.dispose();
            throw new RuntimeException("Content location moved after " +
                    "setResizable(false)" + l);
        }

        if (panel.getLocationOnScreen().y <
                  dialog.getLocationOnScreen().y + dialog.getInsets().top) {
            dialog.dispose();
            throw new RuntimeException(
                        "Wrong content position after setResizable(false)");
        }

        dialog.setResizable(true);
        robot.waitForIdle();
        robot.delay(200);

        l = dialog.getLocationOnScreen();
        if (!l.equals(frameLoc)) {
            dialog.dispose();
            throw new RuntimeException("Decorated frame location moved " +
                    "after setResizable(true)" + l);
        }

        l = panel.getLocationOnScreen();
        if (!l.equals(contentLoc)) {
            dialog.dispose();
            throw new RuntimeException("Content location moved after " +
                    "setResizable(true)" + l);
        }
        if (panel.getLocationOnScreen().y <
                  dialog.getLocationOnScreen().y + dialog.getInsets().top) {
            dialog.dispose();
            throw new RuntimeException(
                         "Wrong content position after setResizable(true)");
        }

        dialog.dispose();
    }
}
 
Example 20
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Sets a {@link Component}'s min, max & preferred sizes to a specific size.
 *
 * @param comp The {@link Component} to work on.
 * @param size The size to set the component to.
 */
public static void setOnlySize(Component comp, Dimension size) {
    comp.setMinimumSize(size);
    comp.setMaximumSize(size);
    comp.setPreferredSize(size);
}