Java Swing FlowLayout wrapInPanel(final JComponent comp, final LayoutManager lm)

Here you can find the source of wrapInPanel(final JComponent comp, final LayoutManager lm)

Description

Wraps a component in a JPanel with the specified layout manager, and returns it.

License

Apache License

Parameter

Parameter Description
comp component to be wrapped
lm layout manager to use for the panel

Return

a wrapping the specified component

Declaration

public static JPanel wrapInPanel(final JComponent comp,
        final LayoutManager lm) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.FlowLayout;

import java.awt.LayoutManager;

import javax.swing.JComponent;

import javax.swing.JPanel;

public class Main {
    /**//from   w ww.  j  a va  2  s. c  o  m
     * Wraps a component in a {@link JPanel} with {@link FlowLayout}, and returns it.
     * 
     * @param comp component to be wrapped
     * @return a {@link JPanel} wrapping the specified component
     *       
     * @see #wrapInPanel(JComponent, LayoutManager)
     */
    public static JPanel wrapInPanel(final JComponent comp) {
        return wrapInPanel(comp, new FlowLayout());
    }

    /**
     * Wraps a component in a {@link JPanel} with the specified layout manager, and returns it.
     * 
     * @param comp component to be wrapped
     * @param lm layout manager to use for the panel
     * @return a {@link JPanel} wrapping the specified component
     *       
     * @see #wrapInPanel(JComponent)
     */
    public static JPanel wrapInPanel(final JComponent comp,
            final LayoutManager lm) {
        final JPanel p = new JPanel(lm);
        p.add(comp);
        return p;
    }
}

Related

  1. addToFlowLayout(JComponent comp, int flowLayoutAlignment)
  2. createPanel(LayoutManager layout, Component... components)
  3. flowLayoutPanel(Component... components)
  4. getFlowLayoutPanelLeftAligned(String title, Component component)
  5. layoutFlow(JComponent... list)