How to put a JFrame in an existing JPanel in Java Swing?

I have an open source java swing application like this: enter image description here http://i47.tinypic.com/dff4f7.jpg

You can see in the screenshot, there is a JPanel divided into two areas, the left and right areas. The left pane has many text links. When I click on the SLA Criteria link, a SLA Criteria popup will appear. A popup is a JFrame object.

Now I am trying to place the popup in the desired area of ​​the JPanel, so this means that the popup will no longer be there, i.e. when I click the SLA Criteria link, its contents will be displayed on the right side of the JPanel. Existing JPanel right pane content will no longer be used. The concept is the same as on the java api documentation page: http://docs.oracle.com/javase/6/docs/api . You click the link in the left frame, you get the content displayed in the right frame.

An example illustration is as follows:

(note: made and edited using the image editor, this is not a real screenshot of the working application)

enter image description here http://i48.tinypic.com/5vrxaa.jpg

So, I would like to know if there is a way to put a JFrame in a JPanel?

I am thinking about using a JInternalFrame, is this possible? Or is there another way?

UPDATE:
Source:
http://pastebin.com/tiqRbWP8 (VTreePanel.java, this is a panel with left and right areas)
http://pastebin.com/330z3yuT (CPanel.java, this is a superclass of VTreePanel, as well as a subclass of JPanel)
http://pastebin.com/MkNsbtjh (AWindow.java, this is a popup)
http://pastebin.com/2rsppQeE (CFrame.java, this is an AWindow superclass, as well as a JFrame subclass)

+4
source share
4 answers

I had source smoothing, I saw that AWindow.java has an internal panel (APanel.java) for storing the contents of the window, and it also has an open method for returning a content panel object (getAPanel ()). In doing so, I can use it to retrieve the contents of the window into another container.

Finally, I decided to use the JTabbedPane in the right pane of VTreePanel to display the contents of the popup.

0
source

Instead of inserting a frame, you want to insert the contents of the frame.

There is (at least) one problem that I see with this.

The menu bar is controlled by the RootPane frame.

Create your new JPanel . Set it to BorderLayout .

Get the menu bar from the frame (using JFrame#getJMenuBar ) and add a new panel to the north position.

Get the ContentPane frames and add them to the center position of the panel.

Undoubtedly, countless other application-specific problems you run into are trying to do this ...

+6
source

No, you do not want to "put a JFrame in a JPanel", and the above illustration does not show this. Instead, it displays a sub window on top (not inside) of another window. If you absolutely need to display a new sub window, I would recommend that you create and display a JDialog. The tutorials will explain how to do this, or if you are stuck in trying to make code, and we will help you deal with it.


Change 1
You indicate:

I need to convert from popup style to jpanel content style. This is exactly the same as the style of the java api documentation page: docs.oracle.com/javase/6/docs/api When you click on the text in the left frame, it does not show a popup, right? Content is displayed right in the right frame. So basically my goal. The source code is quite large. I will try to paste the source code if possible.

What you are looking for is simply to implement MouseListener in a JList or JTable, and when you respond to a click, you will get content based on your choice. This has nothing to do with the placement of a JFrame in a JPanel, and all this involves writing the correct program logic. Again, show it in a modal JDialog, but it's all secondary for writing the right logic without a GUI. You really bark the wrong tree. Forget about JFrames, forget about JPanels for now, and instead focus on how you are going to extract the SLA criteria data when clicked.


Edit 2
I think I see what you are trying to do - use JPanels instead of JFrames and JDialogs and exchange them using CardLayout , which will allow you to exchange views.

+5
source

You cannot put Jframe in JPanel. Instead, you should try to create a separate panel with features like your JFrame and embed it in your JPanel. Since you can put a JPanel in another JPanel but not a JFrame in another JPanel

0
source

Source: https://habr.com/ru/post/1440204/


All Articles