The TableLayou in Groovy's SwingBuilder package supports vertical alignment. But it seems to have no effect when I use it in my code
import groovy.swing.SwingBuilder;
import javax.swing.BorderFactory;
import java.awt.Color;
def ui = new SwingBuilder();
def frame;
frame = ui.frame(title: "Window", bounds: [0, 0, 500, 500], layout: null)
{
tableLayout(size:[400,400],border: BorderFactory.createLineBorder(Color.RED, 2))
{
tr
{
td(valign:'top')
{
label(text:"Label", border: BorderFactory.createLineBorder(Color.BLUE, 2))
}
}
}
}
;
frame.show();
the label appears vertically centered instead of being located at the top. Are additional atrributes required for proper alignment, or doesn't it work at all with TableLayout ?
The
align
andvalign
attributes of TD only take effect on merged columns or rows that have been merged withcolspan
orrowspan
attributes. It's pretty much the same behavior as for HTML tables.The
TableLayout
class is nothing other than a panel that uses theGridBagLayout
. Every table cell (TD) is just the component added to the panel, with specificGridBagLayout
constraints. These constraints are predefined in the classTableLayoutCell
. One of these predefined constraints isweighty
, which is set to the value 0. This means that the panel/table will be always centered vertically.