#Canvas BufferedStrategy causes Error after adding contentPage to JFrame

11 messages · Page 1 of 1 (latest)

lethal trench
#

So I was programming a bit on a Game Engine and have a JFrame and Canvas. Everything and all worked absolutely fine until I added a JPanel as Contentpage to my JFrame using setContentPage(JPanel).
I did this to use Keybindings in my JFrame because and now all of a Sudden my Canvas throws a "java.lang.IllegalStateException: Component must have a valid peer" Exception at the point where I try to use Canvas.createBufferStrategy.

I have no idea why and it only started after I added the setContentPage to my code. Google doesnt return an Answer as does SO.

hearty ospreyBOT
#

This post has been reserved for your question.

Hey @lethal trench! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

deep tiger
#

You had Canvas as a component in frame (so on default contentpane). And you put another panel instead of the default. Right? If yes - that's the problem. Canvas can't exists out of nothing, I believe

lethal trench
#

Wait so the JPanel overwrites the Canvas?

deep tiger
#

it overwrites the panel that was set as default contentpane, if I understood you correctly

lethal trench
deep tiger
lethal trench
deep tiger
hearty ospreyBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.