One of the first things an advanced user will notice is that this tool
will allow you to add subpanels but no tabs. And there are other issues
with creating a form from scratch using the tool. Most advanced users will
actually create some of the form first (especially tabs and other difficult controls)
and then run the panel and pop up the form layout maker to add the easier stuff.
So here is an example file where we want to layout some tabs. When you run this,
the FormLayoutMaker will popup and you'll be able to layout the whole panel as
well as the tabs. You can also add controls to the tab panels. This file is
probably the best way to start if you consider yourself an advanced user. This way,
you can also create controls with factory methods and lay them out using the tool.
Also, keep in mind that when you run this tool, it will look like only one of the controls
was actually added. They are all there, they just all end up in the first row and the
first column. They are essentially on top of each other. You can either move the
top one over to see the next one underneath or prefereable use the Show Component
combobox to bring the one that you want to work with to the top. Lastly, when you
actually generate the xml file from the tool, you will have to modify the code below to
load the LayoutConstraintsManager from the xml file rather than just creating
a new one from scratch. I've included this file in the release archive.
package org.mlc.swing.example;
import org.mlc.swing.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
/**
* @author Michael Connor
*/
public class ExamplePanel extends javax.swing.JPanel
{
JLabel nameLabel = new JLabel ("Name");
JTextField nameText = new JTextField ();
JTabbedPane tabbedPane = new JTabbedPane();
JPanel firstTab = new JPanel();
JPanel secondTab = new JPanel();
JPanel thirdTab = new JPanel();
public ExamplePanel()
{
super ();
org.mlc.swing.layout.LayoutConstraintsManager layoutConstraintsManager =
new org.mlc.swing.layout.LayoutConstraintsManager();
setBorder(com.jgoodies.forms.factories.Borders.DIALOG_BORDER);
this.setLayout (layoutConstraintsManager.createLayout ("panel", this));
firstTab.setLayout (layoutConstraintsManager.createLayout ("firstTab", firstTab));
secondTab.setLayout (layoutConstraintsManager.createLayout ("secondTab", secondTab));
thirdTab.setLayout (layoutConstraintsManager.createLayout ("thirdTab", thirdTab));
LayoutFrame layoutFrame = new LayoutFrame(layoutConstraintsManager);
layoutFrame.setVisible(true);
this.add (tabbedPane, "tabbedPane");
this.add (nameLabel, "nameLabel");
this.add (nameText, "nameText");
tabbedPane.add ("First", firstTab);
tabbedPane.add ("Second", secondTab);
tabbedPane.add ("Third", thirdTab);
}
public static void main (String[] args)
{
ExamplePanel examplePanel = new ExamplePanel();
JFrame frame = new JFrame("Example");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout (new BorderLayout());
frame.getContentPane().add (examplePanel, BorderLayout.CENTER);
frame.setSize(400,500);
frame.setVisible(true);
}
}
When you are done, simply comment out the two lines where you create and show
the layout frame.
|