Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Help with panels

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with panels

    So I want to have an application with multiple panels, one for the login, one that comes the login and another when we press an "add" button.

    I decided to put all of these panels in the same jFrame and just use the setVisible() true or false to show the panels I want and manage the events.

    The problem is that as I use netbeans, I just drag and drop the components where I want. I want the login panel to be in the middle of the frame when I run it, so I put it in the middle and the other panels on its right and left.

    However, when I run the application, the login panel does not appear in the middle at all but in the left side!
    And I don't know how can I manage the emplacement of the panels after running since they don't appear where I want!

    A screenshot :

    Visionneuse images - Noelshack


    thanks !


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Help with panels

    Quote Originally Posted by hiepa View Post
    So I want to have an application with multiple panels, one for the login, one that comes the login and another when we press an "add" button.

    I decided to put all of these panels in the same jFrame and just use the setVisible() true or false to show the panels I want and manage the events.

    The problem is that as I use netbeans, I just drag and drop the components where I want. I want the login panel to be in the middle of the frame when I run it, so I put it in the middle and the other panels on its right and left.
    First, if you want to do something "particular" on user interfaces in AWT/Swing, you must know quite well many aspects about components and layout managers. Without this, you won't go very far ....
    And a "GUI editor" doesn't always help much .... they generally tend to generate code that is verbose, difficult to read and to maintain. Not to say that a GUI editor sometimes can "throw a monkey wrench in your works".

    So please, understand this, and try to think in terms of (AWT/)Swing and not in terms of "dragging components" in a GUI editor.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with panels

    Yes I know that we don't learn much with it, but even the professor in java told us we could use this.

    So can you please help me considering I am using this? The gui is not the most important part in my application since it's for an cryptography course.

    Thankds

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,195
    Thanks
    49
    Thanked 2,172 Times in 2,145 Posts

    Default Re: Help with panels

    Another approach for showing multiple panels would be to use the CardLayout layout manager.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with panels

    I am talking about panels when I run my application, they dont show up at the place I put them in the design!

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,267
    Thanks
    176
    Thanked 821 Times in 764 Posts
    Blog Entries
    5

    Default Re: Help with panels

    Quote Originally Posted by hiepa View Post
    I am talking about panels when I run my application, they dont show up at the place I put them in the design!
    Re-read post #2. In order for you to correctly organize your layout, a familiarity with Layouts is virtually essential. I recommend reading
    A Visual Guide to Layout Managers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    ...and going by Norm's suggestion, you can readily change panels based upon user input using a CardLayout
    How to Use CardLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)

  7. #7
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Help with panels

    border layout might be good for this also..check out LINE_START, CENTER and LINE_END for your panels

    How to Use BorderLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)

    also dont be afraid to use a few different layout managers in the same gui to get it how you want it

Similar Threads

  1. BorderLayouts and graphics panels and such.
    By mstabosz in forum AWT / Java Swing
    Replies: 5
    Last Post: September 12th, 2013, 07:09 AM
  2. [SOLVED] Same buttons getting added to several panels
    By buttcrackbil in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 24th, 2013, 01:04 AM
  3. Help w/ hw , help with panels layouts in frame.
    By Lenjaku in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 30th, 2013, 03:12 PM
  4. adding or removing panels to panels
    By luisp88 in forum AWT / Java Swing
    Replies: 3
    Last Post: November 1st, 2011, 04:37 PM
  5. Help with Layouts and Panels
    By Zookey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 29th, 2011, 05:48 PM