Show the JInternalFrame data in the middle of the form

霸气de小男生 提交于 2020-04-16 05:47:36

问题


I am using JFrame which contains three sections. 1st section is Pane, which contains the 6 menu button (left side). 2nd section is also Pane, which displays the logo of the company on the top. The third section is DesktopPane in which I am using (calling) JInterenalFrame in the DesktopPane.
How to always show the JInterenalFrame content (form data) into the middle of DesktopPane?


回答1:


Third section is DesktopPane in which I am using(calling) JInterenalFrame in the DesktopPane.

A JDesktopPane is used to display multiple JInternalFrames. A JInternalFrame can be dragged around the desktop pane.

From your picture it looks like you just have a single JPanel in that area. Therefore you should not be using JDesktopPanel and JInternalFrame.

Instead you just use a regular JPanel with a CardLayout. This you can replace each panel based on the selection from your menu on the left.

See How to Use CardLayout for more information.

Show the data into middle of the form

The easiest way to do this is to use a JPanel with a GridBagLayout.

So you need to wrap your current panel in a panel with the GridBagLayout.

So the basic code is:

JPanel welcomePanel. = new JPanel( new GridBagLayout() );

welcomePanel.add(currentPanel, new GridBagConstraints());

Now your "currentPanel" will be centered in the "welcomePanel", which has been added to your panel using the CardLayout.



来源:https://stackoverflow.com/questions/61030214/show-the-jinternalframe-data-in-the-middle-of-the-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!