Search code examples
javaswingjframejinternalframejdesktoppane

Show the JInternalFrame data in the middle of the form


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?

Facing issue to show JInternalFrame form data into middle.


Solution

  • 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.