Results 1 to 2 of 2
  1. #1
    Krooger is offline Member
    Join Date
    Nov 2008
    Rep Power

    Question Can someone explain why...

    When I use this code:
    Java Code:
    leftPanel.setBackground(new Color(200));
    leftPanel.setSize(new Dimension(300,300));
    This panel will be added to my main Panel but it will be a little square and not the size I set it to whereas when I use this code:
    Java Code:
    leftPanel.setBackground(new Color(200));
    leftPanel.setPreferredSize(new Dimension(300,300));
    It works exactly as I want it to, and it is a large square with given dimensions.

    Why is it that setSize does not make this panel larger?

    Also when I use this code
    Java Code:
    It will tell me that the size of my Frame is 0,0 even though it is coving my whole screen. How would I get the current height and width in this case?

    Thank You
    Last edited by Krooger; 11-19-2009 at 06:25 AM.

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Pittsburgh, PA
    Rep Power


    setSize() is useless. It is to be called by a LayoutManager,
    but LayoutMangers generally call setBounds().
    The methods to set the Preferred, Minimum, and Maximum sizes
    store the values and send them to the LayoutManager when it asks.

    The Frame sizes are not set until pack() or validate() is called.

Similar Threads

  1. Please explain Java
    By MarkWilson in forum New To Java
    Replies: 7
    Last Post: 07-02-2008, 08:38 AM
  2. Need Help Can anyone explain what this means
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 02-16-2008, 03:13 AM
  3. Can anyone briefy explain what does that mean?
    By Clemenza1983 in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 07:05 AM
  4. Iam new in Java Please explain to me
    By vinaytvijayan in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2007, 11:35 AM
  5. need to explain this code
    By reached in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 10:01 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