Results 1 to 3 of 3

Thread: Automatic resizing of JFrames

  1. #1
    Join Date
    Aug 2010
    Posts
    5

    Automatic resizing of JFrames

    I have a simple application that has a JFrame and a JPanel-derived component. In the JFrame I read a data file and pass an object to the Panel. I would like to cause the panel and the Frame to resize to fit the data I want to display. Currently I have a method on the Panel object that takes the data object and does:

    Dimension prefSize = new Dimension();
    prefSize.height = newObj.numRows()*50;
    prefSize.width = newObj.numCols()*50;
    setPreferredSize(prefSize);
    setSize(prefSize);

    However, this does not result in the panel and frame being resized to accomodate the new preferred size of the panel. However, if I put that same code in the frame object (where it calls the above method on the panel) then the frame (and presumably the panel) *do* resize. But that just doesn't seem right to me. The panel is a child of the frame and setting its size should cause a renegotiation of all the components up the chain, right?

  2. #2
    Join Date
    Aug 2010
    Posts
    5

    Re: Automatic resizing of JFrames

    Never mind. After digging further I found that, in my frame method, after setting the data object on the panel (which does the setting of preferred sizes as above), I simply needed to call pack() to force the frame to resize.

  3. #3
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Automatic resizing of JFrames

    Glad to know that you resolve your issue.

Similar Threads

  1. Resizing digital images
    By ravinderroy in forum Windows Software
    Replies: 3
    Last Post: 24-12-2010, 08:37 AM
  2. Resizing images in InDesign
    By Tamkinat in forum Windows Software
    Replies: 6
    Last Post: 13-07-2010, 12:09 AM
  3. screen self resizing problem
    By Beryl in forum Monitor & Video Cards
    Replies: 4
    Last Post: 08-04-2010, 11:53 PM
  4. Resizing the layer in Photoshop
    By afidelino in forum Windows Software
    Replies: 5
    Last Post: 06-03-2010, 06:20 PM
  5. Disable resizing of JTextPane
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 01:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,927,158.14913 seconds with 17 queries