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

  • SEARCH
  • Home
  • 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 9169341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:51:40+00:00 2026-06-17T15:51:40+00:00

So, I have, at this point, just a simple JFrame with a simple JPanel

  • 0

So, I have, at this point, just a simple JFrame with a simple JPanel inside of it. (That is, it’s contentPane is a JPanel.) There’s a menu bar in the JFrame with a button that converts the current JFrame to a JInternalFrame – it set’s the JFrame‘s contentPane to a pre-existing JDesktopPane and moves the JPanel that was inside the JFrame to the newly created JInternalFrame – and creates a second JInternalFrame with a new JPanel inside it. Here’s my code:

if(ae.getActionCommand().equals("newWindow"))
{
    if(jdp.getComponentCount() > 0)//jdp is the pre-existing JDesktopPane
    {
        //All of the code in this if statement works fine. It's the else in which I am getting problems.
        DefaultInternalFrame dif = new DefaultInternalFrame();//DefaultInternalFrame is an extension of JInternalFrame which is literally nothing more than a JInternalFrame right now.
        jdp.add(dif);
        dif.setContentPane(new DefaultPanel());//Much like DefaultInternalFrame, DefaultPanel is just an extension of JPanel which I plan on adding to, but have not yet.
        dif.setVisible(true);
        dif.moveToFront();
    }else
    {
        //Again, this is where I'm having issues..
        DefaultPanel dp = (DefaultPanel)baseFrame.getContentPane();
        jdp.setVisible(true);
        baseFrame.setContentPane(jdp);
        DefaultInternalFrame dif = new DefaultInternalFrame();
        jdp.add(dif);
        dif.setContentPane(dp);
        dif.setVisible(true);
        dif.moveToFront();

        DefaultInternalFrame dif2 = new DefaultInternalFrame();
        jdp.add(dif2);
        dif2.setContentPane(new DefaultPanel());
        dif2.setVisible(true);
        dif2.moveToFront();
    }
    arrangeHorizontally();//This takes care of resizing and relocating the JInternalFrames. (It is definitely not the problem.)
}

The problem I’m having is that it seems that the JDesktopPane is getting higher priority. That is, after this code has executed, I don’t see two JInternalFrames, I see the JDesktopPane. And it’s not because of issues with size or location of the JInternalFrame. I have checked that extensively (by printing the size and location after the arrangeHorizontally() method.) So, I’m at a loss. Any help?

SSCCE:

private static JFrame f;
private static JDesktopPane desktop;
public static void main(String[] args) throws InterruptedException
{
    desktop = new JDesktopPane();

    f = new JFrame("Test");
    f.setPreferredSize(new Dimension(500,500));
    f.setContentPane(new JPanel());

    f.pack();
    f.setVisible(true);

    Thread.sleep(4000); //Just so you can see the before/after

    JPanel panel = (JPanel)f.getContentPane();

    desktop.setVisible(true);
    f.setContentPane(desktop);

    JInternalFrame inFrame = new JInternalFrame("1");
    desktop.add(inFrame);
    inFrame.setContentPane(panel);
    inFrame.setPreferredSize(new Dimension(200,200));//Just some random size; doesn't matter.
    inFrame.pack();
    inFrame.setVisible(true);

    JInternalFrame inFrame2 = new JInternalFrame("2");
    desktop.add(inFrame2);
    inFrame2.setContentPane(new JPanel());
    inFrame2.setPerferedSize(new Dimension(200,200));
    inFrame2.pack();
    inFrame2.setVisible(true);
}

That should work..
Okay, the SSCCE actually works as it should.. Which makes me wonder, why isn’t the original working?

  • 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-17T15:51:41+00:00Added an answer on June 17, 2026 at 3:51 pm

    The change in content pane might not be enough for the frame to update itself (you think it would be, but hay).

    In your switch code, try adding a call to validate from the frame…

    //Again, this is where I'm having issues..
    DefaultPanel dp = (DefaultPanel)baseFrame.getContentPane();
    jdp.setVisible(true);
    baseFrame.setContentPane(jdp);
    DefaultInternalFrame dif = new DefaultInternalFrame();
    jdp.add(dif);
    dif.setContentPane(dp);
    dif.setVisible(true);
    dif.moveToFront();
    
    DefaultInternalFrame dif2 = new DefaultInternalFrame();
    jdp.add(dif2);
    dif2.setContentPane(new DefaultPanel());
    dif2.setVisible(true);
    dif2.moveToFront();
    
    baseFrame.validate(); // <-- Call me
    

    You might also need a call to repaint, but see where this gets you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that I want to make point-free; (\k t -> chr
I really need help here. I'm desperate at this point. I have NSOperation that
I have this HTML that renders a simple arrow sign pointing towards the right:
I have this simple web service, right now it just looks to see if
I have a set of data that has been displayed as just a simple
I have built a simple interface that fills my entire JFrame. I am using
I have an application that, to this point, is mostly DirectX 10 3D graphics.
I have just started studying JOGL and there is one problem. Below is simple
I have this chart in which if any point in graphs exceeds specific limit
Up to this point we have not yet needed a new masterpage for our

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.