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 setMinimumHeight(JComponent component, int height) {

    component.setMinimumSize(new Dimension((int) component.getMinimumSize().getWidth(), height));
}

From source file:Main.java

public static void setPreferredWidth(JComponent component, int width) {

    component.setPreferredSize(new Dimension(width, (int) component.getPreferredSize().getHeight()));
}

From source file:Main.java

public static void setPreferredHeight(JComponent component, int height) {

    component.setPreferredSize(new Dimension((int) component.getPreferredSize().getWidth(), height));
}

From source file:Main.java

public static void center(Window window) {
    window.pack();//from   w  w  w.  j  a  v  a 2  s  .  c om
    Rectangle bounds = window.getGraphicsConfiguration().getBounds();
    int width = window.getWidth();
    int height = window.getHeight();
    int centerX = bounds.x + bounds.width / 2;
    int centerY = bounds.y + bounds.height / 2;
    window.setLocation(centerX - width / 2, centerY - height / 2);
    window.setPreferredSize(new Dimension(width, height));
}

From source file:Main.java

/**
 * "Fixates" the preferred width of the given label to the given text.
 * //w  ww. j av  a 2  s.c  o  m
 * @param aLabel
 *          the label to fixate, cannot be <code>null</code>;
 * @param aMinimalText
 *          the text to use as minimal width indicator.
 */
public static final void fixLabelWidth(final JLabel aLabel, final String aMinimalText) {
    final FontMetrics fm = aLabel.getFontMetrics(aLabel.getFont());
    final int height = fm.getHeight();

    aLabel.setPreferredSize(new Dimension(fm.stringWidth(aMinimalText), height));
}

From source file:Main.java

public Main() {
    super();/*from   w w w.  j  a v  a  2  s  .  c o  m*/
    JTree tree = new JTree();
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }

    final JScrollPane pane = new JScrollPane(tree) {
        Dimension prefSize = new Dimension(200, 150);

        public Dimension getPreferredSize() {
            return prefSize;
        }
    };

    pane.getVerticalScrollBar().addAdjustmentListener(e -> {
        JViewport vp = pane.getViewport();
        if (vp.getView().getHeight() <= vp.getHeight() + vp.getViewPosition().y) {
            System.out.println("End");
        }
    });

    add(pane);
}

From source file:Main.java

public static void setSize(final Component component, final int width, final int height) {
    if (component != null && width >= 0 && height >= 0) {
        runInEDT(() -> {//from  w  ww  .j a va  2  s .co m
            component.setMaximumSize(new Dimension(width, height));
            component.setMinimumSize(new Dimension(width, height));
            component.setPreferredSize(new Dimension(width, height));
            component.setSize(new Dimension(width, height));
        });
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    Arc2D arc = new Arc2D.Double(0.0, 0.5, w, h, 0.0, 60.0, Arc2D.CHORD);

    g2.draw(arc);// ww w .  ja  v  a 2s  .  co  m

    arc.setArc(new Point(2, 3), new Dimension(w, h), 80.0f, 110.0f, Arc2D.PIE);
    g2.fill(arc);

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 210.0f, 130.0f, Arc2D.OPEN);

    g2.draw(arc);
}

From source file:MainClass.java

MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(300, 50));
    JLabel jl = new JLabel("Name:");
    p.add(jl);//from  w  w  w  . jav  a 2  s  .c om
    JTextField jtf = new JTextField(20);
    jtf.getAccessibleContext().setAccessibleName("Name-entry");
    p.add(jtf);

    AccessibleRelation ar = new AccessibleRelation("connector", jtf);

    AccessibleContext ac = jl.getAccessibleContext();
    ac.getAccessibleRelationSet().add(ar);

    getContentPane().add(p);

    pack();
    setVisible(true);
}

From source file:Main.java

public void init() {
    Box bv = Box.createVerticalBox();
    bv.add(new JButton("Top"));
    bv.add(Box.createRigidArea(new Dimension(120, 90)));
    bv.add(new JButton("Bottom"));
    Box bh = Box.createHorizontalBox();
    bh.add(new JButton("Left"));
    bh.add(Box.createRigidArea(new Dimension(160, 80)));
    bh.add(new JButton("Right"));
    bv.add(bh);//from   w  w  w  .j a  v  a  2 s  .com
    getContentPane().add(bv);
}