Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Settings size for JPanels

  1. #1
    JG4m3r is offline Member
    Join Date
    Mar 2012
    Rep Power

    Default Settings size for JPanels

    So I've got some JPanels that want to give a size, and then add them to a JFrame. My problem is that the JFrame doesn't care about which size I made the JPanels and just makes them as wide as the whole frame. How can I get around this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Settings size for JPanels

    You will want to learn about and use the layout managers to your advantage. If you read the tutorials, you will learn that a JFrame's contentPane uses BorderLayout by default, and you will learn what effect this will have on components added to the container. Some notes:

    • Avoid using null layout and absolute positioning, for on this path lies danger.
    • Avoid setting the sizes of anything if possible, but rather letting components preferred sizes and the layout managers decide how to size the GUI.
    • Call pack() on your top level window after adding all components and prior to calling setVisible(true) so as to get the layout managers to layout their components.
    • It is common to nest JPanels, each using its own layout manager in order to use simple layout managers and achieve complex layouts.
    • Avoid GridBagLayout early on unless absolutely necessary.

    For more, please see: Lesson: Laying Out Components Within a Container
    DarrylBurke likes this.

Similar Threads

  1. Problems with size of JPanels inside JSplitPane
    By kjkrum in forum AWT / Swing
    Replies: 2
    Last Post: 03-23-2012, 03:42 AM
  2. Replies: 2
    Last Post: 04-26-2011, 02:50 PM
  3. Problems regarding JPanels in JPanels
    By ColtonPhillips in forum AWT / Swing
    Replies: 2
    Last Post: 07-19-2010, 08:33 PM
  4. Wrong settings?
    By RonM in forum Eclipse
    Replies: 3
    Last Post: 08-04-2009, 10:35 AM
  5. Setting frame size to the size of an image
    By Yoruichi in forum AWT / Swing
    Replies: 5
    Last Post: 04-22-2009, 04:37 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