Rowlayout layout _java Programming of SWT (JFace) Experience

Source: Internet
Author: User
Tags pack

rowlayout Layout

Compared with filllayout, rowlayout is more flexible and powerful. The user can set properties such as the size, margins, line wrapping, and spacing of the element in the layout.

the style of Rowlayout

Rowlayout can be set in the relevant properties of the layout style, the user can use the "rowlayout. Properties" Way to set the Rowlayout layout style, rowlayout commonly used in the following properties.
Wrap: Indicates whether a child component can wrap (true is a newline).
Pack: Indicates whether the subassembly remains the original size (true to maintain the original size).
Justify: Indicates whether the subassembly is adjusted according to the parent component information.
MarginLeft: Represents the number of pixel points in the current component from the left margin of the parent component.
MarginTop: Represents the number of pixels of the current component from the top margin of the parent component.
MarginRight: Represents the number of pixel points in the current component from the right margin of the parent component.
MarginBottom: Represents the number of pixel points in the current component from the bottom margin of the parent component.
Spacing: Represents the number of pixel points between child components.

In addition, Rowlayout can set the size of each subassembly by RowData, such as "Button.setlayoutdata (new RowData (60, 60)") to set the button's size to (60,60).
Test code:

Copy Code code 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 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 look at the following dynamic (combined composite)
Copy Code code 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 display = new display ();
Shell shell = new shell (display);
int count = 0;
Public layouting () {
Shell.setlayout (New Rowlayout ());

Final composite composite = new Composite (shell, SWT. BORDER);
Composite.setlayout (New Rowlayout ());
Composite.setbackground (SWT, Display.getsystemcolor. 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 ();
}
}
Display.dispose ();
}
public static void Main (string[] args) {
New Layouting ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.