Results 1 to 5 of 5
  1. #1
    kennyblue is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default Which layout to use for this design?

    hi everyone,

    this is my desired design

    JLabel1 //no JTextField here, textfield start on row 2
    JLabel2 JTextField1
    JLabel3 JTextField2
    ... //all are the same after JLabel3


    this can be expand until JLabel 100.. first row must start at top left corner..
    no vertical empty space between JLabel even the panel is resized...


    i've tried to put all these components into 1 JPanel with gridbaglayout but the output is not good.. although can start at top left corner but i cannot delete the empty spaces after JLabel1...

    or maybe u guys got better layout??

    Thank you!

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

    Default

    Quote Originally Posted by kennyblue View Post
    hi everyone,

    this is my desired design
    Java Code:
    JLabel1                        //no JTextField here, textfield start on row 2
    JLabel2                        JTextField1
    JLabel3                        JTextField2
    ... //all are the same after JLabel3
    this can be expand until JLabel 100.. first row must start at top left corner..
    no vertical empty space between JLabel even the panel is resized...


    i've tried to put all these components into 1 JPanel with gridbaglayout but the output is not good.. although can start at top left corner but i cannot delete the empty spaces after JLabel1...

    or maybe u guys got better layout??

    Thank you!
    GridBagLayout should work fine, just make sure to place an invisible component such as an empty JLabel in the upper right corner where you state there should be no JTextField. If it still doesn't work, post an SSCCE here and let's take a look at it.

    Luck!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    No need for an invisible component. colspan = 2 will suffice for the JLabel in the first row.

    no vertical empty space between JLabel even the panel is resized...
    One way to do that is to give the last row a nonzero weighty, fill of NONE and anchor of NORTH. All other rows should have a weighty = 0.

    db

  4. #4
    kennyblue is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    GridBagLayout should work fine, just make sure to place an invisible component such as an empty JLabel in the upper right corner where you state there should be no JTextField. If it still doesn't work, post an SSCCE here and let's take a look at it.

    Luck!
    thx Fubarable!
    ur invisible idea is awesome... but i put it at the bottom as empty space:D

  5. #5
    kennyblue is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by Darryl.Burke View Post
    No need for an invisible component. colspan = 2 will suffice for the JLabel in the first row.


    One way to do that is to give the last row a nonzero weighty, fill of NONE and anchor of NORTH. All other rows should have a weighty = 0.

    db
    Thx Darryl.Burke! finally i solve my problem... i managed to solve it by placing an empty jlabel at the last row with a nonzero weighty....

Similar Threads

  1. Please Help me to do a layout
    By neway003 in forum AWT / Swing
    Replies: 3
    Last Post: 11-03-2010, 06:28 PM
  2. looking for a layout
    By imorio in forum AWT / Swing
    Replies: 3
    Last Post: 08-13-2010, 05:02 PM
  3. Edit layout Layout please help me
    By manhtungtnk28@gmail.com in forum New To Java
    Replies: 4
    Last Post: 11-23-2009, 08:41 AM
  4. Layout manager
    By Nicholas Jordan in forum Java Applets
    Replies: 2
    Last Post: 11-24-2008, 03:02 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
  •