Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:37:58+00:00 2026-06-18T20:37:58+00:00

i have four internal frames and 3 buttons in it .When i hit the

  • 0

i have four internal frames and 3 buttons in it .When i hit the maximize button,maximizes but it overlaps all the frames.But my point is that it should show the minimized frames.
please find the code below

  package Project;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.plaf.basic.BasicInternalFrameUI;

public class Test {

    public Test() throws HeadlessException, PropertyVetoException {
        createAndShowGUI();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new Test();
                } catch (HeadlessException ex) {
                    //Logger.getLogger(MinPanel1.class.getName()).log(Level.SEVERE, null, ex);
                } catch (PropertyVetoException ex) {
                    // Logger.getLogger(MinPanel1.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        });
    }

    private void createAndShowGUI() throws HeadlessException, PropertyVetoException {
        JFrame frame = new JFrame();
        frame.setResizable(true);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        final JDesktopPane jdp = new JDesktopPane() {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(400, 400);
            }
        };

        frame.setContentPane(jdp);
        frame.pack();

        createAndAddInternalFrame(jdp, 0, 0);
        createAndAddInternalFrame(jdp, 200, 0);
        createAndAddInternalFrame(jdp, 400, 0);
        createAndAddInternalFrame(jdp, 600, 0);


        frame.setVisible(true);
    }

    private void createAndAddInternalFrame(final JDesktopPane jdp, int x, int y) throws PropertyVetoException {
        final JInternalFrame jInternalFrame = new JInternalFrame("Test1", true, true, true, true);
        jInternalFrame.setLocation(x, y);
               final JInternalFrame jInternalFrame1 = new JInternalFrame("Test2", true, true, true, true);
JPanel jp= new JPanel();
        JButton jb1 = new JButton("min");
        JButton jb2 = new JButton("[]");
        JButton jb3 = new JButton("X");

        jInternalFrame.setLayout(new GridLayout(2, 2,2,2));
        jInternalFrame1.add(jb1);
        jInternalFrame.setSize(200, 200);//testing
        jInternalFrame.setLayout(new GridLayout(2,2));

        JButton jb= new JButton("min");
       // jInternalFrame.add(jb);
      //  jInternalFrame.add(jb3);
        //jInternalFrame.add(jb2);
        jp.add(jb);
        jp.add(jb2);
        jp.add(jb3);

        jInternalFrame.add(jp);
        jb.addActionListener(new ActionListener()
                {


            @Override
            public void actionPerformed(ActionEvent ae) {
                        try {
                            jInternalFrame.setIcon(true);
                        } catch (PropertyVetoException ex) {
                        }

            }


        });
        jb1.addActionListener(new ActionListener()
                {


            @Override
            public void actionPerformed(ActionEvent ae) {
                        try {
                            jInternalFrame.setIcon(true);
                        } catch (PropertyVetoException ex) {
                        }

            }


        });
        jb2.addActionListener(new ActionListener()
        {


    @Override
    public void actionPerformed(ActionEvent ae) {
        try {
              jInternalFrame.setMaximum(true);

            }
        catch(Exception e)
        {

        }

    }


});jb3.addActionListener(new ActionListener()
{


@Override
public void actionPerformed(ActionEvent ae) {
        try {
            jInternalFrame.dispose();
        } catch (Exception ex) {
        }

}


});

        BasicInternalFrameTitlePane titlePane = (BasicInternalFrameTitlePane) ((BasicInternalFrameUI) jInternalFrame.getUI()).getNorthPane();
        jInternalFrame.remove(titlePane);


        jInternalFrame.setVisible(true);
        jInternalFrame1.setVisible(true);

        jdp.add(jInternalFrame);
                //jdp.add(jInternalFrame1);

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:38:00+00:00Added an answer on June 18, 2026 at 8:38 pm

    You could try: JDesktopPane#setComponentZOrder(Component com, int i).
    As per docs:

    Moves the specified component to the specified z-order index in the
    container. The z-order determines the order that components are
    painted; the component with the highest z-order paints first and the
    component with the lowest z-order paints last. Where components
    overlap, the component with the lower z-order paints over the
    component with the higher z-order.

    …

    Note:

    Not all platforms support changing the z-order of
    heavyweight components from one container into another without the
    call to removeNotify. There is no way to detect whether a platform
    supports this, so developers shouldn’t make any assumptions.

    This will allow you to set the order of the JInternalFrames contained within JDesktopPane.

    UPDATE:

    As per my comment:

    From what I can see its the default behavior and doesnt seem to be
    over com-able by JDesktopPane#setComponentZOrder(Component com, int i)
    when the JInternalFrame is iconified. it works fine when its in normal
    state

    Solution:

    I suggest adjusting the layer on which maximized JInternalFrame is shown:

        jb2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    if (jInternalFrame.isMaximum()) {//restore
                        jInternalFrame.pack();
                    } else {//maximize
                        jInternalFrame.setMaximum(true);
                    }
                    jdp.remove(jInternalFrame);
                    jdp.add(jInternalFrame, JDesktopPane.FRAME_CONTENT_LAYER);
                    jdp.revalidate();
                    jdp.repaint();
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
            }
        });
    

    We must also not forget to add it back to the DEFAULT_LAYER when it is minimized:

        jb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    if (jInternalFrame.getLayer() == JDesktopPane.FRAME_CONTENT_LAYER) {
                        jdp.remove(jInternalFrame);
                        jdp.add(jInternalFrame, JDesktopPane.DEFAULT_LAYER);
                        jdp.revalidate();
                        jdp.repaint();
                    }
                    jInternalFrame.pack();
                    jInternalFrame.setIcon(true);
                } catch (PropertyVetoException ex) {
                }
    
            }
        });
    

    Here is full code:

    enter image description here

    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.HeadlessException;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.beans.PropertyVetoException;
    import javax.swing.JButton;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.SwingUtilities;
    import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
    import javax.swing.plaf.basic.BasicInternalFrameUI;
    
    public class Test {
    
        public Test() throws HeadlessException, PropertyVetoException {
            createAndShowGUI();
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        new Test();
                    } catch (HeadlessException ex) {
                        ex.printStackTrace();
                    } catch (PropertyVetoException ex) {
                        ex.printStackTrace();
                    }
    
                }
            });
        }
    
        private void createAndShowGUI() throws HeadlessException, PropertyVetoException {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
            final JDesktopPane jdp = new JDesktopPane() {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(600, 400);
                }
            };
    
            frame.setContentPane(jdp);
            frame.pack();
    
            createAndAddInternalFrame(jdp, 0, 0);
            createAndAddInternalFrame(jdp, 300, 0);
            createAndAddInternalFrame(jdp, 0, 200);
    
            frame.setVisible(true);
        }
    
        private void createAndAddInternalFrame(final JDesktopPane jdp, int x, int y) throws PropertyVetoException {
            final JInternalFrame jInternalFrame = new JInternalFrame("Test1", true, true, true, true);
            jInternalFrame.setLocation(x, y);
    
            JPanel jp = new JPanel();
    
            JButton jb = new JButton("min");
            JButton jb2 = new JButton("max/restore");
            JButton jb3 = new JButton("close");
    
            jInternalFrame.setLayout(new GridLayout(2, 2));
    
            jp.add(jb);
            jp.add(jb2);
            jp.add(jb3);
    
            jInternalFrame.add(jp);
    
            jb.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    try {
                        if (jInternalFrame.getLayer() == JDesktopPane.FRAME_CONTENT_LAYER) {
                            jdp.remove(jInternalFrame);
                            jdp.add(jInternalFrame, JDesktopPane.DEFAULT_LAYER);
                            jdp.revalidate();
                            jdp.repaint();
                        }
                        jInternalFrame.pack();
                        jInternalFrame.setIcon(true);
                    } catch (PropertyVetoException ex) {
                        ex.printStackTrace();
                    }
    
                }
            });
            jb2.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    try {
                        if (jInternalFrame.isMaximum()) {//restore
                            jInternalFrame.pack();
                        } else {//maximize
                            jInternalFrame.setMaximum(true);
                        }
                        jdp.remove(jInternalFrame);
                        jdp.add(jInternalFrame, JDesktopPane.FRAME_CONTENT_LAYER);
                        jdp.revalidate();
                        jdp.repaint();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
    
                }
            });
            jb3.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    try {
                        jInternalFrame.dispose();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
    
                }
            });
    
            BasicInternalFrameTitlePane titlePane = (BasicInternalFrameTitlePane) ((BasicInternalFrameUI) jInternalFrame.getUI()).getNorthPane();
            jInternalFrame.remove(titlePane);
    
            jInternalFrame.pack();
            jInternalFrame.setVisible(true);
    
            jdp.add(jInternalFrame);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four radio buttons and they're all part of a radioGroup. How can
i have four radio buttons , and i want to set a text for
i have four tables user-question contains two columns: questionID, userID, the questions that the
i have four imageviews in a linear layout in such a manner that only
I have four DB tables in an Oracle database that need to be rewritten/refreshed
I am attempting to find all entries in the 'archive' table that have the
I have four tables. Manufactures, ProductionPlants, ProducitonLine and Machines. Machines are the machines that
I have a Yii web service actionQuery that queries a model based on four
I have four tables that contain some fields 1. user(id, name, email, password, .....)
I have four PictureBoxes (each PictureBox represents one dice) and a Timer that changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.