Results 1 to 5 of 5
  1. #1
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default JFrame reisze window when auto-resized

    I made my frame setResizable(false), however, when I open a fullscreen game or other things that I do, my window sometimes changes resolution eventhough it's not allowed to. How can I detect change in window resolution in such cases and reset it back to two integer variables I've set? I thought of checking for WindowState, so if it's minised or maximised. However, is there a way, so I don't constantly need to check if the window is different resolution, know when the window is ordered by something by other processes to being resized?

    Regards
    augustas656
    Last edited by augustas656; 11-09-2014 at 12:26 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: JFrame reisze window when auto-resized

    setResizable(false) is used to prevent the user from resizing the window. It should not have any effect on the resolution of anything within the window. That is controlled by the GraphicsEnvironment and to some extent, you as the programmer. And my understanding of resolution is the number of pixels per inch supported to render images and text.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default Re: JFrame reisze window when auto-resized

    What I'm saying is that not my code, nor' me as the user has been responsible for a few times the window resized, it happened during me launching a game when I forgot to close my eclipse. How can I prevent this, I don't want to loop to see if the width and height of the window changes, because I believe that can be a bit laggy? So is there a way for me to have an Event Listener for NOT the user resizing the window nor' the game's code only, so it's fired when anything else, any other PROCESS, in this example the game I launched, resizes the window.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: JFrame reisze window when auto-resized

    Well, I can't explain why the window would be resizing on its own. Sometimes, it has to do with timing. If you are doing Swing the repaint mechanisms will happen at different times. This can also happen if you setVisible(true) before packing the JFrame. Is it possible to create a Short, Self Contained, Correct Example to demonstrate the problem. Since I also use Eclipse it is more likely it will behave the same way for me.

    Regards,
    Jim
    Last edited by jim829; 11-09-2014 at 01:07 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    193
    Rep Power
    6

    Default Re: JFrame reisze window when auto-resized

    Ermm, I setVisible before packing. I have a class that extends Canvas and this is my Canvas and JFrame setup:
    Java Code:
    		setMinimumSize(frameDimension);
    		setPreferredSize(frameDimension);
    		setMaximumSize(frameDimension);
    		
    		frame = new JFrame(gameName);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setLayout(new BorderLayout());
    		frame.add(this, BorderLayout.CENTER);
    		frame.setSize(frameWidth, frameHeight);
    		frame.setResizable(true);
    		frame.setLocationRelativeTo(null);
    		frame.setVisible(true);
    		frame.pack();
    gameName, frameWidth and frameHeight are variables as you can tell.
    I'm saying that somehow my window glitched out when I launched a game, so it stretched out eventhough setResizable is set to false. I want to be able to catch these kind of problems with my code and be able to reset them. But what I'm also saying is that I don't want to have some code in my infinite game loop that checks for change in width and height from the defaults, because that is laggy, I want to have an EventListener that is fired when change occurs by any means, not just user resizing the window because I have setResizable to false anyway.

    Also, I have a bit of a problem with Triple Buffering, I have a triple buffer strategy and for some reason it flickers between black and white, but double buffer strategy doesn't. I can easily paint white on my frame, but if I'm resizing, it kind of flickers too.

    Regards
    Augustas656

Similar Threads

  1. Replies: 11
    Last Post: 08-13-2011, 05:27 AM
  2. Only one Jframe window will be opened at time
    By Zamioculcas in forum New To Java
    Replies: 4
    Last Post: 05-29-2011, 01:08 PM
  3. Replies: 4
    Last Post: 04-27-2011, 07:50 AM
  4. JFrame(window) not displaying at all
    By mojisolaowoeye in forum AWT / Swing
    Replies: 1
    Last Post: 07-02-2010, 01:03 PM
  5. auto completion window does not pop-up
    By erdaffi in forum NetBeans
    Replies: 0
    Last Post: 12-11-2007, 12:48 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
  •