Example usage for java.awt Dimension Dimension

List of usage examples for java.awt Dimension Dimension

Introduction

In this page you can find the example usage for java.awt Dimension Dimension.

Prototype

public Dimension(int width, int height) 

Source Link

Document

Constructs a Dimension and initializes it to the specified width and specified height.

Usage

From source file:Main.java

/**
 * Sets the preferred height of the specified component.
 *
 * @param component/*from w  ww. j a va 2  s  . co  m*/
 *            The component
 * @param height
 *            The preferred height
 */

public static void setPreferredHeight(final JComponent component, final int height) {
    component.setPreferredSize(new Dimension(component.getPreferredSize().width, height));
}

From source file:Main.java

public static void centerWithinScreen(final Window wind) {
    if (wind == null) {
        return;/*w ww.j a v a2s. co m*/
    }
    final Toolkit toolKit = Toolkit.getDefaultToolkit();
    final Rectangle rcScreen = new Rectangle(toolKit.getScreenSize());
    final Dimension windSize = wind.getSize();
    final Dimension parentSize = new Dimension(rcScreen.width, rcScreen.height);
    if (windSize.height > parentSize.height) {
        windSize.height = parentSize.height;
    }
    if (windSize.width > parentSize.width) {
        windSize.width = parentSize.width;
    }
    center(wind, rcScreen);
}

From source file:Main.java

public static void addNewLineTo(Container container, int lineHeight) {
    JLabel label = new JLabel();
    label.setPreferredSize(new Dimension(SCREEN_SIZE.width, lineHeight));
    label.setBorder(new LineBorder(Color.BLACK));
    container.add(label);//from   ww  w.java2s  .  c o  m
}

From source file:Main.java

/**
 * This method packs, sets the size, and sets the position of the window given
 *
 * @param window//from  w ww .  j  av  a  2 s. c  om
 */
public static void centerAndPack(Window window) {
    window.pack();
    int x = getWindowXCenter() - (window.getWidth() / 2);
    int y = getWindowYCenter() - (window.getHeight() / 2);
    window.setLocation(x, y);
    window.setMinimumSize(new Dimension(window.getWidth(), window.getHeight()));
}

From source file:Main.java

public static void ensureMinimumSize(JDialog dialog, Dimension size) {
    Dimension s = dialog.getSize();
    Rectangle screen = availableScreenSize();

    if (s.width <= screen.width * 0.15 || s.height <= screen.height * 0.15) {
        // if the window as dimension less than 15% in some direction
        // increase it
        if (size == null) {
            Dimension m = new Dimension((int) (screen.width * 0.625), (int) (screen.height * 0.708));
            dialog.setSize(m);//from  w w  w  . java2s . co  m
        } else {

            Dimension m = new Dimension(Math.max(s.width, size.width), Math.max(s.height, size.height));
            dialog.setSize(m);
        }
    }

}

From source file:Main.java

/**
 * Default textfield design.// w  w  w.  j  ava 2s  .c o  m
 * 
 * @param requireMinWidth Whether the textfield should have a default min. width set.
 * @param contents Initial contents.
 * @return
 */
public static JTextField defaultTextField(boolean requireMinWidth, String contents) {
    JTextField jtf = new JTextField(contents);

    if (requireMinWidth)
        jtf.setPreferredSize(new Dimension(400, jtf.getPreferredSize().height));

    jtf.setBorder(BorderFactory.createCompoundBorder(defaultLineBorder(),
            BorderFactory.createEmptyBorder(0, 5, 0, 0)));
    return jtf;
}

From source file:Main.java

/** Creates a <code>width</code> x <code>height</code> rigid spacer. */
public static Component createRigidSpacer(final int width, final int height) {
    return Box.createRigidArea(new Dimension(width, height));
}

From source file:Main.java

/**
 * @param title/*from  w  w w. j a va  2  s  .com*/
 * @param comp 
 * @return jpanel
 */
public static JPanel createTitledScrollComponent(String title, Component comp) {
    JScrollPane scroll = new JScrollPane(comp);
    scroll.setWheelScrollingEnabled(true);
    scroll.setPreferredSize(new Dimension(1, 1));
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(title));
    panel.setLayout(new BorderLayout());
    panel.add(scroll, BorderLayout.CENTER);
    return panel;
}

From source file:Main.java

private static JPanel getPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(new JLabel("Top"), BorderLayout.NORTH);
    panel.add(new JLabel("Center"), BorderLayout.CENTER);
    panel.add(new JLabel("Bottom"), BorderLayout.SOUTH);
    panel.setPreferredSize(new Dimension(400, 300));
    return panel;
}

From source file:Main.java

public static void setComponentSize(int width, int height, JComponent l) {
    l.setPreferredSize(new Dimension(width, height));
    l.setMinimumSize(new Dimension(width, height));
    if (l instanceof JTextField || l instanceof JComboBox) {
        l.setMaximumSize(new Dimension(Short.MAX_VALUE, height));
    }// w ww. j  a v a2s. co  m
}