Class TLcyTwoColumnLayoutBuilder

java.lang.Object
com.luciad.lucy.gui.TLcyTwoColumnLayoutBuilder

public final class TLcyTwoColumnLayoutBuilder extends Object

Class which facilitates the population of a Container with Components in a two-column layout. Each of those columns can contain a "label" and "editor" component. Methods are also available to add separators or components which span a column or the whole width of the Container.

Once all Components have been added to this builder they can be added to the Container by calling the populate method. Afterwards this builder can no longer be used.

An example usage of this builder:


  //create a frame for the panel
  JFrame frame = new JFrame( "TLcyTwoColumnLayoutBuilder demo" );
  frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

  //use the builder to add components
  TLcyTwoColumnLayoutBuilder builder = TLcyTwoColumnLayoutBuilder.newBuilder();

  builder.addTitledSeparator( "Label-editor" );
  builder.row().
  columnOne( new JLabel( "First name"), new JTextField( 15 ) ).
  columnTwo( new JLabel( "Last name" ), new JTextField( 15 ) ).build();


  builder.addTitledSeparator( "Full width span" );
  JPanel textAreaPanel = new JPanel( new BorderLayout() );
  textAreaPanel.add( new JScrollPane( new JTextArea(15,50) ), BorderLayout.CENTER );
  builder.row().
  spanBothColumns( textAreaPanel ).
  growVertically( true ).
  build();

  builder.addTitledSeparator( "Half width span" );
  builder.row().
  columnOne( new JTextField( "Left span", 30 ) ).
  build();

  builder.row().
  columnTwo( new JTextField( "Right span", 30) ).
  build();


  //create the panel and use the builder to add the components and initialize the layout
  JPanel panel = new JPanel(  );
  builder.populate( panel );

  //add the panel to the frame and show the UI
  frame.getContentPane().add( panel );

  frame.pack();
  frame.setVisible( true );
 

which results in the following UI:
UI created with the builder

You can also use this layout to create panels containing only a single column by placing all the components in the first column, as shown below:


 //create a frame for the panel
 JFrame frame = new JFrame( "Single column demo" );
 frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

 //use the builder to add components
 TLcyTwoColumnLayoutBuilder builder = TLcyTwoColumnLayoutBuilder.newBuilder();

 builder.addTitledSeparator( "Label-editor" );
 builder.row().
 columnOne( new JLabel( "First name"), new JTextField( 15 ) ).build();
 builder.row().
 columnOne( new JLabel( "Last name" ), new JTextField( 15 ) ).build();

 //create the panel and use the builder to add the components and initialize the layout
 JPanel panel = new JPanel(  );
 builder.populate( panel );

 //add the panel to the frame and show the UI
 frame.getContentPane().add( panel );

 frame.pack();
 frame.setVisible( true );
 

which results in the following UI:
Single column UI created with the builder

Since:
2012.0
  • Method Details

    • newBuilder

      public static TLcyTwoColumnLayoutBuilder newBuilder()
      Create a new builder instance
      Returns:
      a new builder instance
    • addTitledSeparator

      public TLcyTwoColumnLayoutBuilder addTitledSeparator(String aSeparatorTitle)
      Adds a titled separator which will span the whole width
      Parameters:
      aSeparatorTitle - The title for the separator. May be empty but must not be null
      Returns:
      this builder instance, allowing to chain method calls
    • populate

      public void populate(Container aContainer)

      Populate aContainer with all Components previously added to this builder. The layout of those components will be as specified when the components were added to this builder.

      After calling this method, this builder can no longer be used.

      Warning: this method will remove all Components which were previously added to aContainer.

      Parameters:
      aContainer - The container. Must not be null
    • row

      Returns a builder for one row of this layout. Once all the components are specified on the RowBuilder, use the RowBuilder#build() method to get a reference back to the updated version of this builder.

      The class javadoc contains a sample snippet illustrating the use of this method.

      Returns:
      a row builder for this builder
      See Also: