Results 1 to 8 of 8
  1. #1
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default JFrame.setResizable(false); problem - makes frame bigger, why?

    When I create a JFrame with a JPanel set to a specific size and set JFrame.setResizable(false); is sometimes makes the frame bigger. Why is that? Is there a solution?

    I have a video demonstrating the problem right here:



    The class I'm using (SmallWindow) to create the frame extends JPanel.
    As you might also see in the video is that the Main JFrame (the bigger one with buttons and textboxes) doesn't have this problem (Both of them have the same structure). This problem seems to only happen sometimes with some classes. Is it a bug?

    My Code:
    Java Code:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class Example extends JPanel{
    	
    	private int width = 200;
    	private int height = 30;
    	private JFrame frame;
    	public Example(){
    		Dimension size = new Dimension(width,height);
    		frame = new JFrame();
    		frame.setResizable(false); // Removing this fixes the problem,
    								// I've used this layout many times and sometimes it doesn't work.
    		setPreferredSize(size);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.add(this);
    		frame.pack();
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    		run();
    	}
    
    	public void run(){
    		while(true){
    			repaint();
    		}
    	}
    
    	public void paintComponent(Graphics g){
    		g.setColor(new Color(255,255,255));
    		g.fillRect(0,0,getWidth(),getHeight());
    		g.setColor(new Color(0,0,0));
    		g.fillRect(0,0,width,height);
    	}
    
    	public static void main(String[]args){
    		new Example();
    	}
    }
    Thanks for answers!
    Last edited by totalspelnerd; 05-25-2013 at 09:22 PM.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    Is it a bug?
    Probably with your code yes. Posting a video doesn't help us.

    Post your Short, Self Contained, Correct Example that demonstrates the problem.

  3. #3
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    Updated the post so the code is there now. Note that the problem only happens sometimes. Sometimes in like certain classes this problem doesn't appear at all.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    Quote Originally Posted by totalspelnerd View Post
    My Code:
    Java Code:
    		while(true){
    			repaint();
    		}
    What?

    Why?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    Quote Originally Posted by DarrylBurke View Post
    What?

    Why?

    db
    I was just making a quick example. I do not code like this normally.

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    That is not a SSCCE. It is not compile. There is no main() method. You don't have code to invoke the class. Also Window is a bad name for a class since AWT has a class by that name. This will confuse people.

  7. #7
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    There you have a fully working code with the problem I'm having (unless I missed something in the copy/pasting). Hope the class name pleases you more now.

  8. #8
    totalspelnerd is offline Member
    Join Date
    Mar 2012
    Location
    Sweden
    Posts
    88
    Rep Power
    0

    Default Re: JFrame.setResizable(false); problem - makes frame bigger, why?

    Fixed!

    adding:
    Java Code:
    frame.setSize(width,height);
    fixed it :D

Similar Threads

  1. Replies: 6
    Last Post: 04-12-2013, 06:33 AM
  2. Replies: 11
    Last Post: 12-20-2011, 08:40 PM
  3. Replies: 2
    Last Post: 11-09-2011, 03:50 AM
  4. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 10:40 AM
  5. Using frame.pack() for resizing JFrame
    By LianaN in forum AWT / Swing
    Replies: 0
    Last Post: 10-30-2010, 12:12 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
  •