简体   繁体   中英

JFrame from one class to internal frame in another class

I currently have 2 classes with JFrame windows.

One has 2 sets of tabbed panes, one on the left, and each tab has a set of tabs at the top.

I have some frame classes that I want to be in the tab panels, and I think (not sure), the only way to do this is using internal frames?

So my question is, is it possible to make a frame from a class, into a JInternalFrame in another class so that, when the tab is clicked, the internal frame appears?

Or is it possible some other way to make a frame appear as one of the tabs in a JTabbedPane ?

I have some JFrame classes that I want to be in the tab panels, and I think (not sure), the only way to do this is using internal frames?

This is not a clear question. In my mind this suggests that you have a view , a display of data and components held in a JFrame, and instead of displaying this information in a separate window, you want several views to be displayed in a single application window, as different JTabbedPanes.

If so, then the solution is to re-write the views that display as JFrames to instead create JPanels, and then place the JPanels into your JTabbedPanes as individual panes. There is no need to use JDesktopPane and JInternalPanes for this.

One quick and dirty (and not always clean) way of extracting a JPanel from your JFrame is to get your JFrame's contentPane -- which is usually a JPanel -- and placing that where needed.

So my question is, is it possible to make a JFrame from a class, into a JInternalFrame in another class so that, when the tab is clicked, the JInternalFrame appears?

This is an XY question. Again the best solution is to get not write your Swing GUI's to extend JFrame since that paints you into a corner that you don't want to be in (as you're finding out), but instead to have your code geared towards creating the much more flexible JPanel, and then placing those JPanels where needed -- in JFrames, in other JPanels, in JDialogs, .... wherever they are needed.

As always, the details of any solution will depend on the details of your current code and your current problem, and so if later you need more specific help, please create and post a valid SSCCE , and include it with your question. Also, please read The Use of Multiple JFrames: Good or Bad Practice? .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM