/* * 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.MeshLayout; public final class MeshLayoutTest { public static void main(String[] args) { JFrame f = new JFrame("MeshLayout Horizontal Test"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JComponent c = (JComponent) f.getContentPane(); //c.setBorder(BorderFactory.createLineBorder(Color.green)); c.setLayout(new MeshLayout(0, 4)); JLabel label; for (int num = 0; num < 11; ++num) { label = new JLabel("element " + num); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label); } long t = System.nanoTime(); f.pack(); System.out.println("time: " + ((System.nanoTime() - t) / 1000000.0) + " ms"); f.setVisible(true); f = new JFrame("MeshLayout Vertical Test"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); c = (JComponent) f.getContentPane(); //c.setBorder(BorderFactory.createLineBorder(Color.green)); c.setLayout(new MeshLayout(4, 0)); for (int num = 0; num < 15; ++num) { label = new JLabel("element " + num); label.setBorder(BorderFactory.createLineBorder(Color.black)); c.add(label); } t = System.nanoTime(); f.pack(); System.out.println("time: " + ((System.nanoTime() - t) / 1000000.0) + " ms"); f.setVisible(true); f = new JFrame("MeshLayout Mixed Test"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); c = (JComponent) f.getContentPane(); MeshLayout layout = new MeshLayout(0, 2); layout.setExpandColumn(1); layout.setExpandRow(4); c.setLayout(layout); label = new JLabel("Name:", JLabel.RIGHT); c.add(label); JTextField text = new JTextField(24); c.add(text); label = new JLabel("Age:", JLabel.RIGHT); c.add(label); text = new JTextField(3); c.add(text); label = new JLabel("City:", JLabel.RIGHT); c.add(label); text = new JTextField(24); c.add(text); label = new JLabel("Social security number:", JLabel.RIGHT); c.add(label); text = new JTextField(16); c.add(text); label = new JLabel("Notes:", JLabel.RIGHT); c.add(label); JTextArea area = new JTextArea(4, 24); c.add(new JScrollPane(area)); c.add(new JLabel()); // empty cell layout = new MeshLayout(0, 3, new Insets(0, 0, 0, 0)); layout.setExpandColumn(0); JPanel buttonsPanel = new JPanel(layout); buttonsPanel.add(new JLabel()); // empty cell buttonsPanel.add(new JButton("OK")); buttonsPanel.add(new JButton("Cancel")); c.add(buttonsPanel); t = System.nanoTime(); f.pack(); System.out.println("time: " + ((System.nanoTime() - t) / 1000000.0) + " ms"); f.setVisible(true); } }