简体   繁体   English

Java:如何对齐JPanel

[英]Java:How to align JPanels

I have this code but it doesn't work: 我有此代码,但它不起作用:

jPanel1.add(jLabel1);
jPanel2.add(jButton1);
jPanel2.add(jButton2);
jPanel3.add(jPanel1,jPanel1.TOP_ALIGNMENT);
jPanel3.add(jPanel2,jPanel2.BOTTOM_ALIGNMENT);
setContentPane(jPanel3);

pack();

Please tell me why! 请告诉我为什么!

You're not setting a LayoutManager on any of the panels. 您没有在任何面板上设置LayoutManager。 This tutorial may be of use to you 教程可能对您有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM