Results 1 to 3 of 3
  1. #1
    JuzerNejm101 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Dinamically adding text fields in defined number of columns

    Hi.

    I'm trying to learn java using NetBeans and I'm a bit stuck here at a problem, so hope some of you guys can guide me to the right path.

    I created a grid layout panel on a frame using swing palette and I created a button which adds up 2 text fields. The idea is to add 2 more text fields by each click. This part works. But what I can't seem to do is make the pairs of text fields appear under the previous pair. The new text fields keep being added in the same row, cutting the dimensions of the previous added text fields.

    I found the info I can define the number of columns on the grid layout by adding the line

    Java Code:
    grid.setColumns(5);
    but this isn't possible because the code where the jPanel is added is not editable.

    Is there a way I can do this? Or must I write the code for the panel manually to be able to define the number of columns?

    Thx

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Dinamically adding text fields in defined number of columns

    Quote Originally Posted by JuzerNejm101 View Post
    I'm trying to learn java using NetBeans and I'm a bit stuck here at a problem, so hope some of you guys can guide me to the right path.

    I created a grid layout panel on a frame using swing palette ...
    Stop right there. You don't learn Java by using a visual designer that isn't a beginners' tool. You learn Java by reading books and/or tutorials and writing code.

    Quote Originally Posted by JuzerNejm101 View Post
    Or must I write the code for the panel manually to be able to define the number of columns?
    Definitely a better option. You can find a lot of guidance in the Tutorial Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    Quote Originally Posted by JuzerNejm101 View Post
    Thx
    Please spell words in full. This is a programming forum, not SMS chat.

    I'm moving this thread to the AWT/Swing section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JuzerNejm101 is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Dinamically adding text fields in defined number of columns

    I'm sorry for the spelling :D

    Thanks for the reply.

    Yeah my choice would be using the full code for learning, but the thing is I am following a program and there are these assignments I have to do. And this one works in the way I have to edit the code to add some stuff in. The thingy was done with visual designer.
    And that's it. I continued working with it and I ran into this problem I can't seem to find a solution too....

    I'll check the links and probably create this part of code manually.

    Thanks once more. :)
    Last edited by JuzerNejm101; 05-20-2012 at 05:31 PM.

Similar Threads

  1. Replies: 1
    Last Post: 05-21-2011, 02:06 AM
  2. Replies: 1
    Last Post: 06-07-2010, 08:10 AM
  3. After adding new columns to my Table
    By joker.med in forum New To Java
    Replies: 5
    Last Post: 04-30-2010, 08:33 PM
  4. variable number of fields with different types
    By Sir G. in forum Advanced Java
    Replies: 11
    Last Post: 03-29-2010, 01:40 AM
  5. Counting the number of columns in a 2D array,
    By KalEl in forum New To Java
    Replies: 9
    Last Post: 10-21-2008, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •