我有这段代码:
//Panell Order
JPanel jorder = new JPanel();
jorder.setLayout(new BoxLayout(jorder, BoxLayout.Y_AXIS));
jorder.setBorder(BorderFactory.createTitledBorder("Order"));
jorder.setPreferredSize(new Dimension(300,250));
//Panell 1
JPanel jp1 = new JPanel();
((FlowLayout)jp1.getLayout()).setAlignment(FlowLayout.CENTER);
JLabel jusuari = new JLabel("User name: ");
JLabel jnom = new JLabel("edetorres");
jp1.add(jusuari);
jp1.add(jnom);
//Panell 2
JPanel jp2 = new JPanel();
((FlowLayout)jp2.getLayout()).setAlignment(FlowLayout.CENTER);
JLabel jproduct = new JLabel("Product: ");
JLabel jcomanda = new JLabel("Tallat");
jp2.add(jproduct);
jp2.add(jcomanda);
//Panel 3
JPanel jp3 = new JPanel();
JButton jserve = new JButton("Serve");
jserve.setAlignmentX(Component.CENTER_ALIGNMENT);
jp3.add(jserve);
//Afegir al panell Order
jorder.add(jp1);
jorder.add(jp2);
jorder.add(jp3);
问题是它返回一个面板,其中三个面板(jp1,jp2,jp3)分开,如下所示:
如何将这3个面板放在一起?