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):
Picture 2 (Exhibit B):
====================================================================================
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.
This may counts as a Java internal bug, or a glitch in programming...
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.
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.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement