Here you can find the source of layoutCompactHorizontal(JComponent... list)
public static JComponent layoutCompactHorizontal(JComponent... list)
//package com.java2s; /***/*from w w w . ja v a 2s. com*/ * Copyright (C) 2010 Johan Henriksson * This code is under the Endrov / BSD license. See www.endrov.net * for the full text and how to cite. */ import java.awt.BorderLayout; import javax.swing.*; public class Main { /** * Compact horizontal layout. No restriction on equal size */ /* public static JComponent compactHorizontal(JComponent left, JComponent right) { JPanel p=new JPanel(new BorderLayout()); p.add(left,BorderLayout.WEST); p.add(right,BorderLayout.EAST); return p; } */ public static JComponent layoutCompactHorizontal(JComponent... list) { JComponent last = list[list.length - 1]; for (int i = list.length - 2; i >= 0; i--) { JPanel p = new JPanel(new BorderLayout()); p.add(list[i], BorderLayout.WEST); p.add(last, BorderLayout.EAST); last = p; } return last; /* JPanel p=new JPanel(new BorderLayout()); p.add(left,BorderLayout.WEST); p.add(right,BorderLayout.EAST); return p;*/ } }