Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2004

Tip: Looking for answers? Try searching our database.

Layout Manager Advice

Thread view: 
Thanasis \(sch\) - 01 Nov 2004 16:47 GMT
Hello to everyone,

i'm new to java and trying to display an (m*n) array of textfields and
labels that have equal size.What layout manager
should i use?GridLayout or GridbagLayout?

Any help would be appreciated
thanasis
Frank - 01 Nov 2004 19:19 GMT
Thanasis (sch) wrote:
> Hello to everyone,
>
[quoted text clipped - 4 lines]
> Any help would be appreciated
> thanasis

Perhaps a JTable would be appropriate?
Thanasis \(sch\) - 01 Nov 2004 19:56 GMT
Hi Frank ,
what i want ro achieve is to build an array of labels and textfields.
The array would 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-textfield6
and so on...8
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));
       //GridLayout nodeSupplies Panel holds only labels and textfields

      for (int i=0;i<currentNodes;i++) // add labels and textfields for
node supplies
       {
           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

===============================================================================
> Thanasis (sch) wrote:
>> Hello to everyone,
[quoted text clipped - 7 lines]
>
> Perhaps a JTable would be appropriate?
Andrew Thompson - 02 Nov 2004 05:12 GMT
On Mon, 1 Nov 2004 20:56:27 +0200, Thanasis (sch) wrote:

> what i want ro achieve is to build an array of labels and textfields.

I notice you also posted this question on c.l.j.help.
Please refrain from multi-posting Thanasis.
<http://www.physci.org/codes/javafaq.jsp#xpost>

I answered it there.  Please restrict your posts to
c.l.j.help for the moment.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Karsten Lentzsch - 02 Nov 2004 09:27 GMT
Thanasis wrote:

You may consider using a JTable for such an array.

GridLayout lays out a grid where all cells have
the same dimension. GridBagLayout won't work for you.

If you need different widths for labels and components,
HIGLayout and the JGoodies FormLayout would do the job.

- Karsten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.