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

    Question Can someone explain why...

    When I use this code:
    Java Code:
    leftPanel.setBackground(new Color(200));
    leftPanel.setSize(new Dimension(300,300));
    mainPanel.add(leftPanel);
    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));
    mainPanel.add(leftPanel);
    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:
    tableFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tableFrame.setExtendedState(Frame.MAXIMIZED_BOTH);	
    tableFrame.setUndecorated(true);
    
    System.out.println(tableFrame.getBounds().getHeight()+"--"+tableFrame.getWidth());
    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 07:25 AM.

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

    Default

    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, 09: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, 04: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, 08:05 AM
  4. Iam new in Java Please explain to me
    By vinaytvijayan in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2007, 12:35 PM
  5. need to explain this code
    By reached in forum New To Java
    Replies: 3
    Last Post: 12-03-2007, 11: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
  •