Java Utililty Methods JComponent Size

List of utility methods to do JComponent Size

Description

The list of methods to do JComponent Size are organized into topic(s).

Method

JPaneladdWithSize(Component c, int width, int height)
Adds a component with the specified size.
Dimension d = c.getPreferredSize();
if (width <= 0) {
    width = d.width;
if (height <= 0) {
    height = d.height;
JPanel p = new JPanel();
...
voidadjustWindowToMinimumSize(final Window window)
adjust Window To Minimum Size
if (window == null)
    return;
final Dimension minSize = window.getMinimumSize();
final Dimension size = window.getSize();
final Dimension newSize = new Dimension(Math.max(size.width, minSize.width),
        Math.max(size.height, minSize.height));
if (!newSize.equals(size)) {
    SwingUtilities.invokeLater(new Runnable() {
...
voidautoFitResize(final JLayeredPane pane, final Component... comps)
auto Fit Resize
pane.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
        for (Component comp : comps) {
            comp.setBounds(0, 0, pane.getWidth(), pane.getHeight());
        pane.revalidate();
        pane.repaint();
...
JComponentchangeSize(JComponent comp, float newSize)
Changes the size of the given component's font.
comp.setFont(comp.getFont().deriveFont(newSize));
return comp;
RectanglecontentSize(final Component component)
Returns component content size limited by component border.
if (component instanceof JComponent) {
    final Insets i = ((JComponent) component).getInsets();
    return new Rectangle(i.left, i.top, component.getWidth() - i.left - i.right,
            component.getHeight() - i.top - i.bottom);
} else {
    return size(component);
JSpinnercreateDoubleSpinner(final double value, final double rangeMinimum, final double rangeMaximum, final double stepSize, final double bigStepSize, final String formatPattern)
create Double Spinner
final SpinnerNumberModel numberModel = new SpinnerNumberModel(value, rangeMinimum, rangeMaximum, stepSize);
final JSpinner spinner = new JSpinner(numberModel);
final JComponent editor = spinner.getEditor();
if (editor instanceof JSpinner.NumberEditor) {
    JSpinner.NumberEditor numberEditor = (JSpinner.NumberEditor) editor;
    final DecimalFormat format = numberEditor.getFormat();
    format.applyPattern(formatPattern);
    numberEditor.getTextField().setColumns(8);
...
booleandiffersSize(AttributeSet style, AttributeSet base)
differs Size
return (StyleConstants.getFontSize(style) != StyleConstants.getFontSize(base));
voiddoSetSize(final Component component, final int width, final int height)
do Set Size
if (component != null && width >= 0 && height >= 0) {
    if (SwingUtilities.isEventDispatchThread()) {
        doSetSizeInEDT(component, width, height);
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                doSetSizeInEDT(component, width, height);
...
voiddoSetSizeInEDT(final Component component, final int width, final int height)
do Set Size In EDT
component.setMaximumSize(new Dimension(width, height));
component.setMinimumSize(new Dimension(width, height));
component.setPreferredSize(new Dimension(width, height));
component.setSize(new Dimension(width, height));
voidemphasizeToolTip()
emphasize Tool Tip
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
toolTipManager.setDismissDelay(100000);
toolTipManager.setInitialDelay(10);
toolTipManager.setReshowDelay(10);