This code may look correct, but there is a slight problem. In a nutshell, I need to specify that all of the fields in column five need to be able to expand horizontally. I do this by making the change shown in Figure 5.
FormLayout layout = new FormLayout("30px, 2dlu, pref, 2dlu, pref:grow", "p,3dlu,p,9dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,pref,3dlu,p,9dlu,p");
Figure 5: | The simple change (shown in a red font) tells the FormLayout to make all of the fields in column five expand horizontally when the container is made wider. |
The simple configuration change from specifying the column as "pref:grow
"
instead of "pref
" solves the horizontal sizing problem. It
instructs the FormLayout to make all of the fields in the fifth column (the data
entry fields) expand horizontally when the user makes the dialog wider.
Now, to solve the vertical sizing problem, the only thing I want to expand is the height of the JTable/JScollPane widget. I don't want the other widgets to be made taller at all. Fortunately this is also easily accomplished, as shown by the code changes in Figure 6.
FormLayout layout = new FormLayout("30px, 2dlu, pref, 2dlu, pref:grow", "p,3dlu,p,9dlu,p,3dlu,p,3dlu,p,3dlu,p,3dlu,fill:pref:grow,3dlu,p,9dlu,p");
Figure 6: | This change (shown in a red font) tells the FormLayout to make the JTable/JScrollPane taller as the user expands the dialog vertically. |
This simple changes does two things. It tells the FormLayout that the
components in this row should both fill the vertical space as our dialog is
resized, and they should also grow as the dialog is resized vertically. It may
not seem obvious, but you do need to specify both of these operators. For
instance, if you only specify "pref:grow
", you'll get the results
shown in Figure 7, which are not desirable; the JTable/JScrollPane just floats
in the middle of the row.
Figure 7: | This shows the effects of wrongly
specifying "pref:grow " instead of "fill:pref:grow ". |
Now if you reverse the problem, and specify only "fill:pref
",
you'' end up with the problem shown in Figure 8, where the JTable/JScrollPane
does not resize horizontally at all.
Figure 8: | This shows the effects of wrongly
specifying "fill:pref " instead of "fill:pref:grow ". |
<<Previous: A brief look at the wrong approach |
Next: Download the source code>> |