Results 1 to 7 of 7
  1. #1
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Best way to make this design

    Hello guys,

    I'm starting with swing and I need to make a frame that should be a design like this:



    My idea is: set the layout of the frame as BorderLayout, than add 3 JPanels and set BorderLayout.DOWN, EAST and WEST.

    Is a good idea?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,596
    Rep Power
    5

    Default Re: Best way to make this design

    Quote Originally Posted by tcms View Post
    Hello guys,

    I'm starting with swing and I need to make a frame that should be a design like this:



    My idea is: set the layout of the frame as BorderLayout, than add 3 JPanels and set BorderLayout.DOWN, EAST and WEST.

    Is a good idea?
    Yes. But you should try it and see for yourself anyway. Shouldn't take you more than 5 minutes.

    Note that BorderLayout is actually the default layout of the frame's content pane. That is another big hint towards self-answering your question.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Best way to make this design

    Thanks for the answer. I made it that way, but I have a problem, the content of cpanel's only appear on the frame when I'm running and change the size of the window with the mouse!
    Last edited by tcms; 10-31-2013 at 01:37 PM.

  4. #4
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Best way to make this design

    Another problem is: I define the size of JPanel, but when I add JButtons they change the JPanel size.

    Java Code:
    content_panel.setMaximumSize(new Dimension(100, 100));
    		content_panel.setLayout(new FlowLayout());
    		for(int i= 0; i< 10; i++){
    			content_panel.add(new JButton("test"));
    		}

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: Best way to make this design

    Quote Originally Posted by tcms View Post
    Thanks for the answer. I made it that way, but I have a problem, the content of cpanel's only appear on the frame when I'm running and change the size of the window with the mouse!
    You're probably doing the pack() and show() calls on the JFrame at the wrong time.
    What does that bit of your code look like?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,596
    Rep Power
    5

    Default Re: Best way to make this design

    Not really problems I see here, just lack of knowledge about Swing. Luckily there is a wonderful tutorial that explains all.

    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    tcms is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Best way to make this design

    Quote Originally Posted by gimbal2 View Post
    Not really problems I see here, just lack of knowledge about Swing. Luckily there is a wonderful tutorial that explains all.

    Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Thanks for the link, helps a lot. But now I have one question, to this porpuse do I really need to create a cpanel for each part of the frame? Because I also can just add my components to JFRame and set the location to look just like my pic.

Similar Threads

  1. Replies: 2
    Last Post: 10-31-2012, 04:31 PM
  2. Preview design vs Run design
    By diamonddragon in forum NetBeans
    Replies: 3
    Last Post: 02-06-2012, 08:11 AM
  3. gui design
    By droidus in forum AWT / Swing
    Replies: 0
    Last Post: 01-28-2012, 12:36 AM
  4. Replies: 4
    Last Post: 07-23-2011, 08:08 PM
  5. GUI design
    By kennyblue in forum AWT / Swing
    Replies: 6
    Last Post: 11-10-2010, 05:59 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
  •