0

I'm playing around with JInternalFrame and I was able to add multiple panels on it but I can't resize each panel. I did use BorderLayout as a layout manager for internal frame.

Here's my code so far

public class Main{
JDesktopPane dp = new JDesktopPane();
JInternalFrame jif = new JInternalFrame(null,false,true,false,true);
public Main(){
    JPanel p = new JPanel(){{
        setOpaque(false);
    }};
    JPanel p1 = new JPanel(){{
        setBackground(Color.red);
    }};
    JPanel p2 = new JPanel(){{
        setBackground(Color.blue);
    }};
    JPanel p3 = new JPanel(){{
        setBackground(Color.orange);
        setSize(1300,1300);
    }};
    ((javax.swing.plaf.basic.BasicInternalFrameUI)jif.getUI()).setNorthPane(null);
    jif.setVisible(true);
    jif.setSize(460,430);

    jif.setLayout(new BorderLayout());

    jif.getContentPane().add(p2, BorderLayout.SOUTH);
    jif.add(p1, BorderLayout.CENTER);
    jif.getContentPane().add(p3, BorderLayout.EAST);


    jif.add(p, BorderLayout.NORTH);
    jif.setBackground(Color.black);

    dp.add(jif);


    JFrame f = new JFrame();
    f.add(dp);
    f.setSize(500, 500);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}


public static void main(String[] args){
    new Main();
}

}

As always, Thanks!

iamLinker
  • 88
  • 1
  • 10
  • Most layouts don't respect a component's size but rather its preferredSize. – Hovercraft Full Of Eels Mar 28 '16 at 11:52
  • Thanks for your explanation, it worked for me, but one last thing, can you explain why layouts do not respect size but rather the preferred size? – iamLinker Mar 28 '16 at 12:00
  • See this post http://stackoverflow.com/questions/1783793/java-difference-between-the-setpreferredsize-and-setsize-methods-in-compone – Eames Mar 28 '16 at 12:08

0 Answers0