Results 1 to 5 of 5
  1. #1
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default Components Layout in a JPanel

    Hi,

    Could someone tell me how to assign a specfic layout to each component in a Panel? For example, if I want to display something as follows using Box class:

    .....Name......
    [..............]

    [ ...... ] age
    [ ...... ] ID

    Where the brackets are the textfields and dots are spaces.
    Which methods are out there to change to this layout? Can anyone give a very good source to refer to?

    Thanks heaps.
    Last edited by jboy; 10-11-2009 at 01:40 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You will often use nested layouts; that is several JPanels, some nested inside of others, each using their own layouts. Popular layouts include the Sun Swing (or AWT) layouts which you can read about here: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    Also, there's the MigLayout which you can read up on here: MiG Layout Java Layout Manager for Swing and SWT

  3. #3
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default

    I have now decided to manage my layout using the GridBagLayout, the problem is I don't know how to add a text field and two radio buttons on the first row and a text field and two radio buttons on th second row without any borders. So it is actually one panel with 6 different components. How can I set their position for each on the panel?

    Thanks!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    For general questions on how to use this complex layout, I doubt any of us can explain things better than is already done in the tutorial. You can find this tutorial by going to my first link above. Please give it a read, and then give it a try. Much luck.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    As an aside, I personally try to avoid the GridBagLayout due to its complexity. If I can solve the problem in a simpler manner, I will. If you really want GridBag functionality in an easier layout, take a serious look at the Mig Layout.

    YMMV

Similar Threads

  1. Layout problem / add components from another class
    By ehochedez in forum AWT / Swing
    Replies: 9
    Last Post: 09-02-2009, 10:42 AM
  2. How to place components on JPanel
    By deshprateek in forum AWT / Swing
    Replies: 1
    Last Post: 02-22-2009, 05:34 AM
  3. Inconsistent layout w/dynamic resize of components
    By donb2000 in forum AWT / Swing
    Replies: 3
    Last Post: 07-26-2008, 02:40 PM
  4. JPanel / layout problems
    By Warhorsei in forum AWT / Swing
    Replies: 4
    Last Post: 06-04-2008, 05:26 AM
  5. Removing components from JPanel
    By Echilon in forum New To Java
    Replies: 0
    Last Post: 12-30-2007, 04:05 PM

Posting Permissions

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