Rowlayout Layout
Compared with filllayout, rowlayout is flexible and has powerful functions. You can set attributes such as the size, margin, line feed, and spacing of child elements in the layout.
Rowlayout Style
In rowlayout, you can set the layout style with related attributes. You can set the layout style of rowlayout through "rowlayout. Attribute". common attributes in rowlayout are as follows.
Wrap: indicates whether the child widget can wrap (true indicates a wrap ).
Pack: indicates whether the sub-component maintains the original size (true indicates the original size ).
Justify: indicates whether the child component is adjusted according to the parent component information.
Marginleft: number of pixels between the current component and the left of the parent component.
Margintop: number of pixels between the current component and the top margin of the parent component.
Marginright: number of pixels between the current component and the right of the parent component.
Marginbottom: number of pixels at the bottom margin of the parent widget.
Spacing: the number of pixels separated between child components.
In addition, rowlayout can set the size of each sub-component through rowdata. For example, "button. setlayoutdata (New rowdata (60, 60)" sets the size of the button to (60, 60 ).
TestCode:
Copy code The Code is as follows: Package swt_jface.demo2;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. layout. rowdata;
Import org. Eclipse. SWT. layout. rowlayout;
Import org. Eclipse. SWT. Widgets. Button;
Import org. Eclipse. SWT. Widgets. display;
Import org. Eclipse. SWT. Widgets. List;
Import org. Eclipse. SWT. Widgets. shell;
Public class rowlayoutsample {
Display display = New Display ();
Shell shell = new shell (Display );
Public rowlayoutsample (){
Rowlayout = new rowlayout ();
// Rowlayout. Fill = true;
// Rowlayout. Justify = true;
// Rowlayout. Pack = false;
// Rowlayout. type = SWT. vertical;
// Rowlayout. Wrap = false;
Shell. setlayout (rowlayout );
Button button1 = new button (shell, SWT. Push );
Button1.settext ("button1 ");
Button1.setlayoutdata (New rowdata (100, 35 ));
List list = new list (shell, SWT. Border );
List. Add ("item 1 ");
List. Add ("item 2 ");
List. Add ("item 3 ");
Button button2 = new button (shell, SWT. Push );
Button2.settext ("button #2 ");
// Shell. setsize (120,120 );
Shell. Pack ();
Shell. open ();
While (! Shell. isdisposed ()){
If (! Display. readanddispatch ()){
Display. Sleep ();
}
}
Display. Dispose ();
}
Public static void main (string [] ARGs ){
New rowlayoutsample ();
}
}
let's take a look at the dynamic below (combined with composite) copy Code the code is as follows: Package swt_jface.demo2;
Import Org. eclipse. SWT. SWT;
Import Org. eclipse. SWT. events. controlevent;
Import Org. eclipse. SWT. events. controllistener;
Import Org. eclipse. SWT. events. selectionadapter;
Import Org. eclipse. SWT. events. selectionevent;
Import Org. eclipse. SWT. layout. rowlayout;
Import Org. eclipse. SWT. widgets. button;
Import Org. eclipse. SWT. widgets. composite;
Import Org. eclipse. SWT. widgets. display;
Import Org. eclipse. SWT. widgets. shell;
public class layouting {
display = New Display ();
shell = new shell (Display);
int COUNT = 0;
Public layouting () {
shell. setlayout (New rowlayout ();
Final composite = new composite (shell, SWT. Border );
Composite. setlayout (New rowlayout ());
Composite. setbackground (display. getsystemcolor (SWT. color_yellow ));
Composite. addcontrollistener (New controllistener (){
Public void controlmoved (controlevent e ){
}
Public void controlresized (controlevent e ){
System. Out. println ("Composite resize .");
}
});
Button buttonadd = new button (shell, SWT. Push );
Buttonadd. settext ("Add new button ");
Buttonadd. addselectionlistener (New selectionadapter (){
Public void widgetselected (selectionevent e ){
Button button = new button (composite, SWT. Push );
Button. settext ("button #" + (count ++ ));
Composite. layout (true );
Composite. Pack ();
Shell. layout (true );
Shell. Pack (true );
}
});
shell. Pack ();
// shell. setsize (450,100);
shell. open ();
while (! Shell. isdisposed () {
If (! Display. readanddispatch () {
display. sleep ();
}< BR >}< br> display. dispose ();
}< br> Public static void main (string [] ARGs) {
New layouting ();
}< BR >}