I have developed one frame on which I used GridBagLayout to arrange textfields of 12X12. i.e., total 144 textfields on frame. Now I want to differentiate these text fields with colored line after each 3 columns and three rows as shown in the following diagram. I tried in many ways, but I couldn't find the solution. Please suggest. Below is the some part of my code. Thanks in advance.
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12
| | |
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12
| | |
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12
-------------------------------
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12
| | |
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12
| | |
1 2 3 | 4 5 6 | 7 8 9 | 10 11 12
-------------------------------- |
1 2 3 | 4 5 6................
. .
. .
.
Please consider the each number as one textfield in diagram.
JTextField jt[][]=new JTextField[12][12];
for(int i=0;i<jt.length;i++)
{
for(int j=0;j<jt.length;j++)
{
jt[i][j] = new JTextField(1);
constraints.gridx=j;
consraints.gridy=i;
gridbag.setConstraints(jt[i][j],cons);
c.add(jt[i][j]);
jt[i][j].setHorizontalAlignment(JTextField.CENTER);
jt[i][j].setFont(new Font("TimesNewRoman",Font.BOLD,14));
jt[i][j].setDocument(new JTextFieldLimit(2));
}
}
You could us a JSeparator or, break each group of 3x3 fields into there own separate panes and use a LineBorder.
So long as you've setup you fields properly, you should be able to get the compound panels/
LineBorder
to workUPDATE
Sorry, it should have been
MatteBorder
:PNow, obviously, you need to figure out how you'd seed your fields, but basically, I'd just pass in the fields you want to be used (such as 2D array for example).
Or with separators :P
Or variations on the same theme
UPDATED with field management