Back to Buoy resources page

BOutline

BOutline is a widget container that draws a border around the widget it holds. It is commonly used to distinguish between several groups of widgets displayed in the same window. Using a BOutline to draw a border is really simple.

Usually, you would place a widget in a widget container or a BFrame using something like :

widgetContainer.add( widget );

or

setContent( widget );

To add a border around the widget, you basically use the following code :

widgetContainer.add( new BOutline ( widget, border ) ); where border is typically created by BorderFactory (see Swing documentation). The BOutline class also provides static methods for common borders, like bevel borders and so on. Let's have a look at the example code. There are two radio buttons packed in a column container:

 ColumnContainer rc = new ColumnContainer();
 cc.setDefaultLayout( new LayoutInfo( LayoutInfo.WEST, LayoutInfo.NONE, new Insets( 3, 3, 3, 3 ), null ) );
 RadioButtonGroup radioGroup = new RadioButtonGroup();
 cc.add( new BRadioButton( "Tweedledum", true, radioGroup ) );
 cc.add( new BRadioButton( "Tweedledee", false, radioGroup ) );

This column container is placed inside a BOutline (the border of which is a bevel border), which is in turn placed at the center of the border container which is set to be the content of the BFrame. The bevel border BOutline can be created using a static "utility" method.

bc.add( BOutline.createBevelBorder( cc, true ), BorderContainer.CENTER );

figure 1

AWhat if we want a border which is not provided by the static methods ? In that case it possible the create a border using the Swing BorderFactory static calls and then create a BOutline using this border, like in example 2:

bc.add( new BOutline( cc, BorderFactory.createTitledBorder( BorderFactory.createRaisedBevelBorder(), "Alice quizz" ) ), BorderContainer.CENTER );

Which yields the following result:

figure 2

One last word : BOutline widget containers don't make use of layouts (LayoutInfo), since they just add a border to the widget they hold.

 import java.awt.Insets;
 import javax.swing.border.*;
 import javax.swing.BorderFactory;
 import buoy.event.*;
 import buoy.widget.*;
 
 
 /**
  *  BOutline demo
  *
  *@author     Fran├žois Guillet
  *@created    2004/06/21
  */
 public class BOutlineDemo
          extends BFrame
 {
 
     /**
      *  Constructor for the BButtonDemo object
      */
         public BOutlineDemo()
     {
         super( "BOutline demo" );
 
         ColumnContainer cc = new ColumnContainer();
         cc.setDefaultLayout( new LayoutInfo( LayoutInfo.WEST, LayoutInfo.NONE, new Insets( 3, 3, 3, 3 ), null ) );
 
         RadioButtonGroup radioGroup = new RadioButtonGroup();
         cc.add( new BRadioButton( "Tweedledum", true, radioGroup ) );
         cc.add( new BRadioButton( "Tweedledee", false, radioGroup ) );
 
         BorderContainer bc = new BorderContainer();
         bc.setDefaultLayout( new LayoutInfo( LayoutInfo.CENTER, LayoutInfo.NONE, new Insets( 10, 10, 10, 10 ), null ) );
 
         //Example 1
         bc.add( BOutline.createBevelBorder( cc, true ), BorderContainer.CENTER );
 
         //Example 2
         //bc.add( new BOutline( cc, BorderFactory.createTitledBorder( BorderFactory.createRaisedBevelBorder(), "Alice quizz" ) ), BorderContainer.CENTER );
 
         BButton answerButton = new BButton( "Answer" );
         bc.add( answerButton, BorderContainer.SOUTH );
 
         setContent( bc );
 
         answerButton.addEventLink( CommandEvent.class, this, "doQuit" );
         addEventLink( WindowClosingEvent.class, this, "doQuit" );
 
         pack();
         setVisible( true );
 
     }
 
 
     /**
      *  Quit
      */
     private void doQuit()
     {
         System.exit( 0 );
     }
 
 
     /**
      *  Main
      *
      *@param  args  The command line arguments
      */
     public static void main( String[] args )
     {
         new BOutlineDemo();
     }
 }