/* * Copyright © 2006, 2007 Roberto Mariottini. All rights reserved. * * Permission is granted to anyone to use this software in source and binary forms * for any purpose, with or without modification, including commercial applications, * and to alter it and redistribute it freely, provided that the following conditions * are met: * * o Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * o The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * o Altered source versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ import java.awt.*; import javax.swing.*; import javax.swing.border.*; import net.mariottini.layout.PileLayout; public final class PileLayoutTest { public static void main(String[] args) { JFrame f = new JFrame("PileLayout Horizontal Test"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container c = f.getContentPane(); c.setLayout(new PileLayout(PileLayout.DIRECTION_HORIZONTAL)); JLabel label = new JLabel("Top aligned"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_TOP); label = new JLabel("Middle aligned"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_MIDDLE); label = new JLabel("Bottom aligned"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_BOTTOM); label = new JLabel("Fitted"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_FIT); label = new JLabel("Expanded"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_EXPAND); long t = System.nanoTime(); f.pack(); f.setSize(f.getSize().width + 50, f.getSize().height + 50); f.setVisible(true); System.out.println("time: " + ((System.nanoTime() - t) / 1000000.0) + " ms"); f = new JFrame("PileLayout Vertical Test"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); c = f.getContentPane(); c.setLayout(new PileLayout(PileLayout.DIRECTION_VERTICAL)); label = new JLabel("This component is left aligned"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_LEFT); label = new JLabel("This component is center aligned"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_CENTER); label = new JLabel("This component is right aligned"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_RIGHT); label = new JLabel("This component is fitted"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_FIT); label = new JLabel("This component is expanded"); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label, PileLayout.ALIGN_EXPAND); t = System.nanoTime(); f.pack(); f.setSize(f.getSize().width + 50, f.getSize().height + 50); f.setVisible(true); System.out.println("time: " + ((System.nanoTime() - t) / 1000000.0) + " ms"); f = new JFrame("PileLayout Mixed Test"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); c = f.getContentPane(); c.setLayout(new PileLayout(PileLayout.DIRECTION_VERTICAL)); label = new JLabel("Name:"); c.add(label); JTextField text = new JTextField(24); c.add(text, PileLayout.ALIGN_FIT); label = new JLabel("Age:"); c.add(label); text = new JTextField(3); c.add(text); label = new JLabel("City:"); c.add(label); text = new JTextField(24); c.add(text, PileLayout.ALIGN_FIT); label = new JLabel("Social security number:"); c.add(label); text = new JTextField(16); c.add(text); label = new JLabel("Notes:"); c.add(label); JTextArea area = new JTextArea(4, 24); c.add(new JScrollPane(area), PileLayout.ALIGN_EXPAND); JPanel buttonsPanel = new JPanel(new PileLayout(PileLayout.DIRECTION_HORIZONTAL, new Insets(0, 0, 0, 0))); buttonsPanel.add(new JLabel(), PileLayout.ALIGN_EXPAND); buttonsPanel.add(new JButton("OK")); buttonsPanel.add(new JButton("Cancel")); c.add(buttonsPanel, PileLayout.ALIGN_FIT); t = System.nanoTime(); f.pack(); f.setVisible(true); System.out.println("time: " + ((System.nanoTime() - t) / 1000000.0) + " ms"); } }