开发者

How to set more panels in Java

开发者 https://www.devze.com 2022-12-24 19:35 出处:网络
I need to开发者_JAVA百科 get two JPanels into one JApplet. paneel = new RekenmachinePaneel(); nummer = new NummerPaneel();

I need to开发者_JAVA百科 get two JPanels into one JApplet.

paneel = new RekenmachinePaneel();
nummer = new NummerPaneel();
setContentPane(paneel);

Now I need to get the nummer panel to show up beneath the paneel. How should I do that?


If you want to add both panels you will have to create a third one:

JPanel myPanel = new JPanel();
myPanel.add(paneel);
myPanel.add(nummer);
setContentPane(myPanel);

If you want to get the number of panels you have inside an specific component use this:

int no = yourComponent.getComponents().length;


You can use a layout to position them.

setLayout(new GridLayout(0,1));
add(paneel);
add(nummer);


Make the layout as null.

paneel.setLayout(null);
nummer.setLayout(null);

By setting the layouts to null, you can move any panels over any panel. But its not recommended as you will not be using the power of layouts (form, border, box etc.,)

Also you would need to the location of the panels properly.

paneel.setLocation(x2,y2);
nummer.setLocation(x1,y1);
0

精彩评论

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

关注公众号