Java JComponent Size getPreferredSizeComponent(JComponent component)

Here you can find the source of getPreferredSizeComponent(JComponent component)

Description

Wraps a JComponent into a JPanel using a BorderLayout , adding it to WEST.
If using this method for e.g.

License

Open Source License

Parameter

Parameter Description
component the component

Return

the preferred size component

Declaration

public static JComponent getPreferredSizeComponent(JComponent component) 

Method Source Code


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

import java.awt.*;

import javax.swing.*;

public class Main {
    /**//from  www.  ja v  a2  s  .  com
     * Wraps a {@link JComponent} into a {@link JPanel} using a {@link BorderLayout}, adding it to WEST.<br>
     * If using this method for e.g. a {@link JCheckBox} and adding it to a layout, the {@link JCheckBox} won't
     * span the entire space and thus, it won't change the checked state if clicking outside of it.
     *
     * @param component the component
     * @return the preferred size component
     */
    public static JComponent getPreferredSizeComponent(JComponent component) {
        JPanel pWrap = new JPanel(new BorderLayout());
        pWrap.add(component, BorderLayout.WEST);
        return pWrap;
    }
}

Related

  1. getMaxSize(JComponent[] components)
  2. getOptimalScreenSize(Container container, Dimension currentDim)
  3. getPreferredSize(JComponent component, int width)
  4. getPreferredSize(String html, boolean width, int prefSize)
  5. getPreferredSize(Window window)
  6. getScreenSize()
  7. getScreenSize(Component invoker)
  8. getSize(byte[] data)
  9. getSize(Component c, int sizeflag)