Friday, 10 February 2012

SwingBuilder Series: Layouts - BoxLayout

java.awt.BoxLayout allows multiple components to be laid out either vertically or horizontally. The SwingBuilder node for using de BoxLayout is boxLayout() . It is used the same as borderLayout() node was. You can declare the layout node, and then you can start adding components.

However each time you declare a new boxLayout() node, you should tell the layout what the components' direction is going to be: vertical or horizontal


There is a shortcut for using BorderLayout easier, java.awt.Box which is a container with a BoxLayout layout. There're two variants of the box() node: vbox(
) and hbox() for arranging component vertically or horizontally respectively.

These last two nodes are more popular for doing quick prototyping like the following sample:
import java.awt.BorderLayout as BL
import java.awt.Dimension
panel(preferredSize:new Dimension(500,200)){
vbox{
hbox{
textField(id:'title')
comboBox(id:'language',preferredSize:new Dimension(125,0))
button(id:'executeButton',text:'Add')
}
scrollPane(){
table(id:'mess
ages'){
tableModel(){
propertyColumn(header:'language',propertyName:'language')
propertyColumn(header:'text',propertyName:'text')
}
}
}
}
}

This code looks like this:




1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete