Jump to content
  • Advertisement
Sign in to follow this  
tom_mai78101

This may counts as a Java internal bug, or a glitch in programming...

This topic is 2373 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

Here I present to you a Java bug I recently found while watching Mojang livestream their MoJam for Humble Bundle.

The following two pictures are shown below. The highlighted part of the code are the only lines that are changed.

Picture 1 (Exhibit A):

Capture1-1.png

Picture 2 (Exhibit B):

Capture2-1.png


====================================================================================

In Picture 1, at lines 103 and 104, when the JFrame first starts to become visible, and then disable resizing, it causes a bug in JFrame.pack() method and display an inaccurate size of the JFrame's border size.

However, in Picture 2, when lines 103 and 104 are switched around, everything is correctly displayed.

So, what should I do about this? Should I report this or just leave it, as I have fixed it by using the solution in Picture 2? Thanks for viewing.

Share this post


Link to post
Share on other sites
Advertisement
JFrame uses whatever default layout manager is, which may interpret dimensions differently.

Either set a layout manager or just set Game as contentPane.

Layout managers are a pain.

Should I report this or just leave it[/quote]

Aside from likely not being a bug, Swing was abandoned years ago, only thing still on life support is JavaFX and neither Sun nor Oracle cared about Swing foundation, so IMHO it's not worth reporting it.

Share this post


Link to post
Share on other sites
When I set my Game to ContentPane, it creates a thin, black boundary (border) around the inside of the JFrame. How do you make it fill up the entire JFrame (without the borders)?

Or just set JFrame.setResizable() to false, then set JFrame.setVisible() to true?

Looks like I should just use the bugginess as a feature, instead of complaining about it.

Share this post


Link to post
Share on other sites
Absolute sizes are next to impossible to implement correctly. For example, they need to take into account dpi setting of the screen, something which is buggy in just about every OS. There's also problems with aspect ratio. All of these become an issue once fonts are involved.

Swing also abstracts away the crucial API each OS uses to provide such information, but the abstractions aren't enough.

Unless you want to spend most of development trying to tweak around all kinds of inconsistencies, just design UI to be dynamic.

Or make it fixed size, but center it on screen (BorderLayout.CENTER or similar). Trying to match it to outer borders of JFrame is simply not worth it.

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!