GridLayout problem
Hi to everyone,
what i want ro achieve is to build an array of labels and textfields.
I want the array to have 6 columns and a variable number of rows depending on
the number of components(labels and textfields) provided.
I want my array to be displayed as follows:
label1-textfield1 - label2-textfield2 - label3-textfield3
label4-textfield4 - label5-textfield5 - label6-textfield6
label7-textfield7 - label8-textfield8 - label9-textfield9
and so on...
I tried something like the following but it doesn't work when there are (i.e
8 elements ( 4 labels and 4 textfields))
================================================== =============================
int rows=1;
int cols=6;
int elements=2*currentNodes;
if (elements<=6){
rows =1;
cols=elements;
}
else if (elements>=7)
{
while (elements>=7)
{
elements = elements-6;
rows++;
}
}
Panel nodeSuppliesPanel = new Panel(new GridLayout(rows,6,2,2));
for (int i=0;i<currentNodes;i++)
{
nodeSuppliesLabels[i]=new Label("b("+(i+1)+")",Label.CENTER);
nodeSuppliesPanel.add(nodeSuppliesLabels[i]);
nodeSuppliesTextFields[i]=new TextField();
nodeSuppliesTextFields[i].setText(String.valueOf(nodeSupplies[i]));
nodeSuppliesPanel.add(nodeSuppliesTextFields[i]);
}// end for
================================================== ==================
wishes
thanasis
|