Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2004, 04:16 PM
Registered User
 
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old December 1st, 2004, 01:30 PM
Authorized User
 
Join Date: Nov 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sonicDace Send a message via MSN to sonicDace Send a message via Yahoo to sonicDace
Default

thanasis,

I recommend placing the labels and textfields inside a panel, and then place the panel inside the component that's using the GridLayout.

You can set the rows dynamically using the setRows( int rows ) method of the GridLayout manager. for that you'll need a reference the Gridlayout outside of your panel constructor.

Hope this helps

thanks
 
Old December 1st, 2004, 02:59 PM
Registered User
 
Join Date: Oct 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

many thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
GridLayout :: help needed kanoorani Java Basics 2 January 22nd, 2006 01:02 PM
Is GridLayout Mode gone in VS2005? Aaron Edwards ASP.NET 2.0 Basics 1 January 2nd, 2006 04:22 AM
GridLayout and Panels spudgun2005 J2EE 0 September 12th, 2005 01:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.