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

public static void addNewLineTo(Container container) {
    JLabel label = new JLabel();
    label.setPreferredSize(new Dimension(SCREEN_SIZE.width, 0));
    container.add(label);//from   w  ww.j a  v a 2s .c  o m
}

From source file:Main.java

public static void showInfo(Component parent, String message) {
    Component cmp = new JScrollPane(new JTextArea(message));
    cmp.setPreferredSize(new Dimension(400, 400));
    JOptionPane.showMessageDialog(parent, cmp, "Information", JOptionPane.INFORMATION_MESSAGE);
}

From source file:Main.java

public static Dimension getStringSize(JComponent c, FontMetrics metrics, String text) {
    int width = SwingUtilities2.stringWidth(c, metrics, text);
    int height = metrics.getHeight();
    return new Dimension(width, height);
}

From source file:Main.java

/**
 * Create a component buffer of width w and height h
 * /*from www  .jav  a2 s  .  c o  m*/
 * @param width
 * @param height
 * @return
 */
public static Component createBufferPanel(int width, int height) {
    Container buffer = new Container();
    buffer.setMinimumSize(new Dimension(width, height));
    buffer.setPreferredSize(new Dimension(width, height));
    buffer.setMaximumSize(new Dimension(width, height));

    return buffer;
}

From source file:Main.java

/**
 * Returns the size available from given point to in component to bottom right of component screen.
 *///ww w  .  jav a 2  s. co  m
public static Dimension getScreenSizeAvailable(Component aComp, int anX, int aY) {
    Rectangle rect = getScreenBounds(aComp, anX, aY, true);
    Point sp = getScreenLocation(aComp, anX, aY);
    return new Dimension(rect.x + rect.width - sp.x, rect.y + rect.height - sp.y);
}

From source file:Main.java

public static void padPreferredWidthDeep(Component component, int padding) {
    if (component instanceof Container) {
        for (Component child : ((Container) component).getComponents()) {
            padPreferredWidthDeep(child, padding);
        }//from   ww w .j  a  v  a  2 s  .  co m
    }
    component.setPreferredSize(new Dimension((int) component.getPreferredSize().getWidth() + padding,
            (int) component.getPreferredSize().getHeight()));
}

From source file:Main.java

public static JPanel createPanelWithFixedSize(final int preferredWidth) {
    final JPanel p = new JPanel() {
        @Override/*from  w w  w.ja va 2 s  . c  om*/
        public Dimension getMinimumSize() {
            return getPreferredSize();
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(preferredWidth, super.getPreferredSize().height);
        }

        @Override
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    return p;
}

From source file:Main.java

/**
 * Returns a preferrable window size for the application
 * @return/* w  w w.ja  v a2s .c  om*/
 */
public static Dimension getPreferrableWindowSize() {
    int margin = 100;
    Dimension size = getEffectiveScreenSize();
    float aspect = size.width / (size.height * 1.0f);
    int newHeight = size.height - margin;
    int newWidth = (int) (newHeight * aspect);
    return new Dimension(newWidth, newHeight);
}

From source file:Main.java

public static JPanel getComponentColumn(JComponent[] components) {
    JPanel columnPanel = new JPanel();
    columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.PAGE_AXIS));

    for (int i = 0; i < components.length; i++) {
        components[i].setMinimumSize(new Dimension(components[i].getPreferredSize().width, ROW_HEIGHT));
        components[i].setPreferredSize(new Dimension(components[i].getPreferredSize().width, ROW_HEIGHT));
        components[i].setMaximumSize(new Dimension(components[i].getPreferredSize().width, ROW_HEIGHT));
        components[i].setAlignmentX(JComponent.LEFT_ALIGNMENT);
        columnPanel.add(components[i]);/*from   w  w  w  . jav  a  2 s  .  c  o  m*/
    }
    return columnPanel;
}

From source file:Main.java

public static Dimension getScreenDimension() {
    int width = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode()
            .getWidth();/*  ww w  .  j a  va2 s  .  c om*/
    int height = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode()
            .getHeight();

    Dimension d = new Dimension(width, height);
    return d;
}