Sign in to follow this  
tom_mai78101

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

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):

[img]http://i1207.photobucket.com/albums/bb464/tom_mai78101/Capture1-1.png[/img]

Picture 2 (Exhibit B):

[img]http://i1207.photobucket.com/albums/bb464/tom_mai78101/Capture2-1.png[/img]


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

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
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.

[quote]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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this