......... JLabel ll=NewJLabel (Dlg.getnametext () + ":" +Dlg.getiptext (), Ii[index], jlabel.left); TMP=NewJPanel ();//Add a label to this panelTmp.setlayout (NewFlowLayout (Flowlayout.center)); Tmp.setbackground (NewColor (255, 0, 255)); /** BoxLayout layout is a pain in the egg, a panel x is the boxlayout layout, if the panel adds a panel y then y will fill the x panel ! If you add a panel z, then y, Z will be covered with the X panel! But you can set the scale of the Y,Z panel *! If x is adding a button or label, you cannot control its size .... No words anymore! * * below I practice adding a label to the panel TMP and then adding TMP to the QQP panel! This will allow you to control the size of the label! * To add a new panel, set the preferredsize! of the previous panel Ensure that each label is in a moderate distance! * That is to guarantee all the added panel height of the sum = = Qqp.getheight (); * */ intCNT = Qqp.getcomponentcount ();//show the number of QQ friends! if(CNT >= 1) qqp.getcomponent (CNT-1). Setpreferredsize (NewDimension (250, 60));//60 indicates the height of the default label inth = qqp.getheight ()-cnt*60; if(H < 0) h=60;//if all the height of the high and the height of the QQP panel, then directly the default height, the remaining display is given to the vertical scroll bar! Tmp.setpreferredsize (NewDimension (250, h)); Tmp.add (LL); Qqp.add (TMP); Qqp.add (TMP); .....//See below!
Java simulates the layout of the QQ Friends panel (BoxLayout problem)