Results 1 to 4 of 4

Thread: JFrame resizing

  1. #1
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default JFrame resizing

    I currently have my JFrame set to be unresizable for simplicity's sake.

    Now I want to set it to be ONLY vertically resizable but I only want two components to change (vertically) in size when this happens. I want everything else to remain exactly the same.

    Can anyone help?
    Last edited by carderne; 07-22-2009 at 06:54 PM.

  2. #2
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Bumpity bump.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Now I want to set it to be ONLY vertically resizable
    You can set a JFrame's minimum size via setMinimumSize, but this doesn't work (as far as I know for maximum size). If you absolutely need maximum size, then you can use a ComponentListener similar to this one:
    Java Code:
        // assuming panelWidth is some int, say 800
        addComponentListener(new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
            Dimension size = ResizePanel.this.getSize();
            ResizePanel.this.setPreferredSize(new Dimension(panelWidth, size.height));
            frame.pack();
          }
        });
    but it's kind of a kludge as it allows for a partial brief re-size of width before snapping back to the desired width.

    but I only want two components to change (vertically) in size when this happens
    You may wish to study your layout managers tutorial for this one. BoxLayout comes to mind here, and I think you'll want to set the maximumsize of your components.

  4. #4
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Thanks. Maybe I'll make the JFrame completely resizable and then just set the maximum sizes for all of the components and not allow them to resize horizontally at all. SOLVED.

Similar Threads

  1. JFrame resizing problem
    By Bluefox815 in forum AWT / Swing
    Replies: 7
    Last Post: 02-24-2011, 08:56 PM
  2. Resizing Images in JPanel??
    By NoNickName in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 11:19 PM
  3. panel resizing
    By kumar_gemi in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 03:51 AM
  4. Image Resizing and DPi
    By Rob_ in forum Java Applets
    Replies: 4
    Last Post: 11-27-2008, 03:21 PM
  5. Image resizing
    By alley in forum Java 2D
    Replies: 2
    Last Post: 11-13-2007, 11:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •