lukas.coenig
lukas.coenig

Reputation: 551

Can JFrames be put in a parent window?

I have a project which creates several JFrames and shows them as separate windows. This can be quite confusing, so I want to collect all these frames in a parent window.

I am aware of the concept of JInternalFrame which would certainly work in principle, but the project is quite large, and the JFrames rather complex, so converting them individually to JInternalFrame seems more or less unfeasible to me (particularly due to JInternalFrame behaving a little differently in some respects such as mouse events).

Is there a way to take the JFrames themselves and put them in a parent window? (Or is there another solution I'm not thinking of?)

Upvotes: 0

Views: 901

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347214

The short answer is no. This is why we generally discourage extending from JFrame (or top level containers) directly. You need to try a move the content out of the JFrame to something like JPanel. This will allow you to make better decisions about how to present the content.

The simplest solution is to go through your code and replace extends JFrame with extends JPanel and correct for any compiler errors that it produces. You could also add a static method that wraps an instance of the container into a JFrame should you need it.

Upvotes: 1

Related Questions