Jump to content
  • Advertisement
Sign in to follow this  
Brendyn_Todd

Odd Offset With Jframe?

This topic is 773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've created a JFrame with the size of 640x480. I notice that when checking for a boundary that prevents movement past 0,0 works normally, however when I check for a boundary at 640 or 480 it does not stop at the screens edge.

 

It seems that 640 and 480 are offset of the screens visual edges, the visual edges seem to be about 50 pixels offset from the actual max boundary allowing movement past the visual edges.

 

Does anyone know why this happens and how the offset may be fixed without constantly checking for (640-50) or vice versa?

 

(Posting JFrame code in case the creation is the problem)

public class Test {

    JFrame frame;

    public Test(){

        frame = new JFrame("Test");
        frame.setSize(640,480);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);

    }
}
Edited by Brendyn_Todd

Share this post


Link to post
Share on other sites
Advertisement
It's been a long time since I did anything with Swing but I would assume the size you specify is the size of the whole window (including borders, title bar and whatnot), not the size of the client area.

Share this post


Link to post
Share on other sites
I believe BitMaster is correct. This is why it is common to use a Canvas or JPanel to draw your actual game to, and set the size on that. then you can just call the pack() function on your JFrame.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!