Java Swing UIManager createFlow(final Object... components)

Here you can find the source of createFlow(final Object... components)

Description

create Flow

License

LGPL

Declaration

public static JPanel createFlow(final Object... components) 

Method Source Code


//package com.java2s;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;

import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.UIManager;

import javax.swing.plaf.metal.MetalLookAndFeel;

public class Main {
    static final String LAF_METAL = MetalLookAndFeel.class.getName();

    public static JPanel createFlow(final Object... components) {
        return createFlow(FlowLayout.LEFT, 0, components);
    }//from   w  w  w. jav a  2 s.  co  m

    public static JPanel createFlow(final int align, final int gap, final Object... components) {
        final JPanel jp = new JPanel(new FlowLayout(align, gap, gap));
        jp.setBorder(BorderFactory.createEmptyBorder());
        for (final Object component : components) {
            if (component instanceof Component) {
                initComponentHeight((Component) component);
                jp.add((Component) component);
            } else if (component instanceof Number) {
                jp.add(Box.createHorizontalStrut(((Number) component).intValue()));
            }
        }
        return jp;
    }

    public static void initComponentHeight(final Component... components) {
        if (components == null) {
            return;
        }
        for (final Component component : components) {
            if ((component instanceof JComboBox) || (component instanceof JButton)) {
                component.setPreferredSize(new Dimension(component.getPreferredSize().width, 22));
            } else if (component instanceof JTextField) {
                final String lf = UIManager.getLookAndFeel().getClass().getName();
                int i = 22;
                if (lf.equals(LAF_METAL)) {
                    i = 23;
                }
                component.setPreferredSize(new Dimension(component.getPreferredSize().width, i));
            }
        }
    }
}

Related

  1. canChangeSize()
  2. clearErrorLabel(JLabel label)
  3. configureStandardUI()
  4. createDefaultHorizontalAlignment()
  5. createErrorLabel(String errorMsg)
  6. createHorizontalAlignment(int scoutAlign)
  7. createHorizontalLine()
  8. createMessageLabel(String message)
  9. createTabbedPane(int tabPlacement)