开发者

Can we add panel inside panel to create nested tabbed menu?

开发者 https://www.devze.com 2022-12-18 01:13 出处:网络
I have written one small code to add three panels to a main panel but the code is not working. JPanel jp,child1,child2,child3;

I have written one small code to add three panels to a main panel but the code is not working.

JPanel jp,child1,child2,child3; JTabbedPane jtp;

public Panel4()
{
    jtp=new JTabbedPane();
    jp=new JPanel();
    child1=new JPanel();
    child2=new JPanel();
    child3=new JPanel();
    jtp.addTab("C开发者_开发知识库hild1",child1);
    jtp.addTab("Child2",child2);
    jtp.addTab("Child3",child3);
    jp.setLayout(null);
    jtp.setVisible(true);
    jp.add(jtp);
    jp.setVisible(true);
}

Here i am adding this jp to another JTabbedPane which is added in a JFrame. I can see the panel jp but not the childs (child1,child2,child3). Please suggest what is wrong here.


replace

jp.setLayout(null);

by

jp.setLayout(new BorderLayout());


Hi all thanks for answers, i solved the problem. Previously i was adding childs to JTabbedPane and adding JTabbedPane to JPanel and again adding JPanel to the main JTabbedPane. Instead i added the JTabbedPane which contains the childs to the main JTabbedPane. This is confusing but thanks for the help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号