Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JGoodies FormLayout/PanelBuilder

843805Sep 5 2006
Hi all,

I am not sure if this post belongs under this forum but here goes. I have just started to use the formlayout from jgoodies and have found that it works different to the way that gridbagconstaints handles to focus traversal of components ie with gridbaglayout the focus follows order that the component has been added to the layout manager where as in the formlayout manager this is not the case ie it seems that the focus traverses the order of the rows and columns.

I was trying to achieve the focus to stay in the Vehicle data group and then shift across the Customer data group. I have tried using different panelbuilder object for each section of grouped data and this does fix my problem but I could not make the form look as per the below example. Any hints anyone??

Below is my example code...
import javax.swing.*;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

class Testing extends JFrame
{
        JLabel comrec_noLbl = new JLabel();
        JTextField comrec_noFld = new JTextField();

        JLabel form_idLbl = new JLabel();
        JTextField form_idFld = new JTextField();

        JLabel order_noLbl = new JLabel();
        JTextField order_noFld = new JTextField();

        JLabel load_noLbl = new JLabel();
        JTextField load_noFld = new JTextField();

        JLabel plant_noLbl = new JLabel();
        JTextField plant_noFld = new JTextField();

        JLabel trans_typeLbl = new JLabel();
        JTextField trans_typeFld = new JTextField();

        JLabel customer_noLbl = new JLabel();
        JTextField customer_noFld = new JTextField();

        JLabel carrier_noLbl = new JLabel();
        JTextField carrier_noFld = new JTextField();

        JLabel product_cdLbl = new JLabel();
        JTextField product_cdFld = new JTextField();

        JLabel truck_noLbl = new JLabel();
        JTextField truck_noFld = new JTextField();

        JLabel driver_noLbl = new JLabel();
        JTextField driver_noFld = new JTextField();

        JLabel destination_cdLbl = new JLabel();
        JTextField destination_cdFld = new JTextField();

        JLabel err_readLbl = new JLabel();
        JTextField err_readFld = new JTextField();

        JLabel err_columnLbl = new JLabel();
        JTextField err_columnFld = new JTextField();

        JLabel vehicle_tagLbl = new JLabel();
        JTextField vehicle_tagFld = new JTextField();

        JLabel vehicle_noLbl = new JLabel();
        JTextField vehicle_noFld = new JTextField();

        JLabel trailer_tagLbl = new JLabel();
        JTextField trailer_tagFld = new JTextField();

        JLabel trailer_noLbl = new JLabel();
        JTextField trailer_noFld = new JTextField();

        JLabel bdlead_tagLbl = new JLabel();
        JTextField bdlead_tagFld = new JTextField();

        JLabel bdlead_noLbl = new JLabel();
        JTextField bdlead_noFld = new JTextField();

        JLabel gross_wtLbl = new JLabel();
        JTextField gross_wtFld = new JTextField();

        JLabel gross_hourLbl = new JLabel();
        JTextField gross_hourFld = new JTextField();

        JLabel gross_minLbl = new JLabel();
        JTextField gross_minFld = new JTextField();

        JLabel gross_dayLbl = new JLabel();
        JTextField gross_dayFld = new JTextField();

        JLabel gross_monthLbl = new JLabel();
        JTextField gross_monthFld = new JTextField();

        JLabel gross_yearLbl = new JLabel();
        JTextField gross_yearFld = new JTextField();

        JLabel tare_wtLbl = new JLabel();
        JTextField tare_wtFld = new JTextField();

        JLabel tare_hourLbl = new JLabel();
        JTextField tare_hourFld = new JTextField();

        JLabel tare_minLbl = new JLabel();
        JTextField tare_minFld = new JTextField();

        JLabel tare_dayLbl = new JLabel();
        JTextField tare_dayFld = new JTextField();

        JLabel tare_monthLbl = new JLabel();
        JTextField tare_monthFld = new JTextField();

        JLabel tare_yearLbl = new JLabel();
        JTextField tare_yearFld = new JTextField();

        JLabel print_statusLbl = new JLabel();
        JTextField print_statusFld = new JTextField();

        JLabel hostupd_statusLbl = new JLabel();
        JTextField hostupd_statusFld = new JTextField();

        JTextField grossTimeDateFld = new JTextField();
        JTextField tareTimeDateFld = new JTextField();
 
   public Testing()
  {
    setLocation(300,100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
 

        FormLayout layout = new FormLayout(
            "right:pref,3dlu,20dlu,"      +
            "3dlu,right:pref,3dlu,20dlu," +
            "20dlu,right:pref,3dlu,30dlu," +
            "3dlu,right:pref,3dlu,20dlu",
            "p, 3dlu, p, 3dlu, p, 3dlu, " +
            "p, 3dlu, p, 3dlu, p, 3dlu, " +
            "p, 3dlu, p, 3dlu, p, 3dlu, " +
            "p, 3dlu, p, 3dlu, p, 3dlu, " + 
            "p, 3dlu, p, 3dlu, p, 3dlu");

        // Specify that group columns 1,5,9,13 have equal widths.
        // and that columns 3,7,15 have equal widths
        layout.setColumnGroups(new int[][]{{1,5,9}, {3,7}});

        // Obtain a reusable constraints object to place components in the grid
        CellConstraints cc = new CellConstraints();

        // The builder holds the layout container.
        PanelBuilder builder = new PanelBuilder(layout);
        builder.setDefaultDialogBorder();

        builder.addLabel("Record No",           cc.xy  (1,3));
        builder.add(comrec_noFld,               cc.xy  (3,3));
        builder.addLabel("Print Status",        cc.xy  (5,3));
        builder.add(print_statusFld,            cc.xy  (7,3));
        builder.addLabel("Form Id",             cc.xy  (1,5));
        builder.add(form_idFld,                 cc.xy  (3,5));
        builder.addLabel("Read Error",          cc.xy  (5,5));
        builder.add(err_readFld,                cc.xy  (7,5));
        builder.addLabel("Transaction Type",    cc.xy  (1,7));
        builder.add(trans_typeFld,              cc.xy  (3,7));
        builder.addLabel("Error Column",        cc.xy  (5,7));
        builder.add(err_columnFld,              cc.xy  (7,7));
        builder.addLabel("Host Update Status",  cc.xy  (1,9));
        builder.add(hostupd_statusFld,          cc.xy  (3,9));

        builder.addSeparator("Vehicle Data",    cc.xyw (1,15,7));
        builder.addLabel("Plant ID",            cc.xy  (1,17));
        builder.add(plant_noFld,                cc.xy  (3,17));
        builder.addLabel("Driver No",           cc.xy  (5,17));
        builder.add(driver_noFld,               cc.xy  (7,17));
        builder.addLabel("Vehicle Tag",         cc.xy  (1,19));
        builder.add(vehicle_tagFld,             cc.xy  (3,19));
        builder.addLabel("Vehicle No",          cc.xy  (5,19));
        builder.add(vehicle_noFld,              cc.xy  (7,19));
        builder.addLabel("Trailer Tag",         cc.xy  (1,21));
        builder.add(trailer_tagFld,             cc.xy  (3,21));
        builder.addLabel("Trailer No",          cc.xy  (5,21));
        builder.add(trailer_noFld,              cc.xy  (7,21));
        builder.addLabel("B/Double Tag",        cc.xy  (1,23));
        builder.add(bdlead_tagFld,              cc.xy  (3,23));
        builder.addLabel("B/Double No",         cc.xy  (5,23));
        builder.add(bdlead_noFld,               cc.xy  (7,23));
        builder.addSeparator("",                cc.xy  (1,25));
        builder.addLabel("Gross Weigh",         cc.xy  (1,27));
        builder.add(gross_wtFld,                cc.xy  (3,27));
        builder.add(grossTimeDateFld,           cc.xyw (5,27,3));
        builder.addLabel("Tare Weigh",          cc.xy  (1,29));
        builder.add(tare_wtFld,                 cc.xy  (3,29));
        builder.add(tareTimeDateFld,            cc.xyw (5,29,3));

        builder.addSeparator("Customer Data",   cc.xyw (9,15,7));
        builder.addLabel("Customer",            cc.xy  (9,17));
        builder.add(customer_noFld,             cc.xy  (11,17));
        builder.addLabel("Destination",         cc.xy  (13,17));
        builder.add(destination_cdFld,          cc.xy  (15,17));
        builder.addLabel("Carrier",             cc.xy  (9,19));
        builder.add(carrier_noFld,              cc.xy  (11,19));
        builder.addLabel("Order No",            cc.xy  (13,19));
        builder.add(order_noFld,                cc.xy  (15,19));
        builder.addLabel("Product",             cc.xy  (9,21));
        builder.add(product_cdFld,              cc.xy  (11,21));
        builder.addLabel("Load No",             cc.xy  (13,21));
        builder.add(load_noFld,                 cc.xy  (15,21));
    
    getContentPane().add(builder.getPanel());
    pack();
  }
  public static void main(String[] args)
  {
     new Testing().setVisible(true);
  }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2006
Added on Sep 5 2006
0 comments
243 views