Java JComponent Width setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height)

Here you can find the source of setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height)

Description

set Bounds And Center Horizontally

License

Open Source License

Declaration

public static void setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Container;

import javax.swing.JComponent;

public class Main {
    public static void setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height) {
        Container parent = component.getParent();
        int parentWidth = parent.getWidth();
        int paddingOnBothSides = parentWidth - width;
        x = paddingOnBothSides / 2;//w ww  .j a va2 s .c o  m
        component.setBounds(x, y, width, height);
    }
}

Related

  1. initComponent(JComponent component, String title, int width, int height)
  2. makeEqualWidth(JComponent... components)
  3. makeSamePreferredWidth(JComponent... comps)
  4. normalizeWidth(JComponent... components)
  5. sameWidth(JComponent[] components, int width)
  6. setComponent3Width(JComponent c, int width)
  7. setComponentWidth(final JComponent component, final int width)
  8. setMaximumWidth(final JComponent component, final int width)
  9. setMaximumWidth(JComponent component, int width)