Battle SWT layout

xiaoxiao2021-03-06  71

A actual SWT layout EFLY original (participating: 724, expert points: 1010) Published: 2002-11-24 10:22 in the afternoon: 2002-11-25 9:28 AM: 1.0 Read: 9050 times

Standard SWT Layout FillLayout: In the container with the same size single line or single column RowLayout: Use several options (Fill, WRAP, SPACING, JUSTIFY, TYPE) to customize components in a single line or multi-line. GridLayout : Similar to Swing GridLayout in the way in plaid, the component formlayout (new feature of SWT 2.0): Arrange the component by defining the "Paste" position of the component, the relative components being referenced can be parental components, or Is other components in the same container. In SWT, the layout class can be customized by the user. In a simple layout, it is also relatively simple in simple layout. But the usual layout is more complicated, and it is very accurate. Regardless of the complexity, it can be done by GridLayout or FormLayout. Usually GridLayout and FormLayout can make the same effect, but use formlayout more efficient, it is more simple to make RESIZE-caused layout is simpler like GridLayout. The following is a brief introduction to the use of FormLayout. Layout effect layout implementation 1. First define the window and its blank edge display.getDefault (). Dispose (); // Remove the platform core start screen display = new display (); shell = new shell (display, swt.title) FormLayout Layout = new formlet (); layout.marginheight = 10; layout.marginwidth = 20; shell.setLayout (Layout); shell.Settext ("User Login"); 2. Create the elements on the window, where the following two Button is inclusive by a component using RowLayout. Name = new label (shell, swt.none); Name.Settext ("User Name)); Nametext = New Text (Shell, Swt.Single | SWT.BORDER); Pass = New Label (shell, swt.none); Pass.setText ("password"); passtext = new text (shell, swt.single | swt.border); passtext.sechochar ('*'); passtext.settabs (2); bottom = new Composite (shell, SWT. None); RowLayout RowLayout = New RowLayout (); RowLayout.Justify = true; // Justify definition component is scattered in the container, effect is similar to Swing FlowLayout Bottom.setLayout (RowLayout); 3. Define the location of the Name tag. Its top edge is from the parent component (window shell).

Formdata Data = new formdata (); data.top = new formattachment (15, 0); Name.setLayOutdata (data); 4. Define the location of the Name text. Its top edge in the center position of the Name tag (this is not correct expression, but the program is explained so, in fact, its central position is on the same horizontal line with the Name label), and there is 10 points from the right side of the left side. Data = new formdata (); data.top = new formattachment (name, 0, swt.center); data.left = new formattachment (name, 10, swt.right); nameText.setLayoutData (DATA); 5. Definition Pass Label location. Its top edge has 10 points from the bottom of the Name label. Data = new formdata (); data.top = new formattachment (name, 10, swt.bottom); pass.setLayOutdata (data); 6. Define the location of the pass text. Its top edge is aligned with the left side of the Name text box on the left side of the Name Tag. Data = new formdata (); data.top = new formattachment (pass, 0, swt.ceter); data.left = new formattachment (Nametext, 0, swt.left); passtext.setLayOutdata (data); 7. Definition bottom The location of the component. Its top edge is 15 points from the bottom of the pass tag, and the left side is aligned with the left side of the Pass tag, right side to the right side of the pass text.

Data = new formData (); data.top = new formattachment (pass, 15, swt.bottom); data.right = new formattachment (pass, 0, swt.left); data.right = new formattachment (passtext, 0, SWT.RIGHT); bottom.setLayoutData (data); the complete source code import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse .swt.graphics.Rectangle; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; 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.Label; import org.eclipse. SWT.WIDGTS.SHELL; import org.eclipse.swt.widgets.text; import cn.com.efly.clientframe.core.hook; / ** * @Author Efly * @version 1.0.0 ,11 / 22/02 * / public final class loginui {private display; private shell shell; private composite bottom; p rivate Label name; private Label pass; private Text nameText; private Text passText; private Button ok; private Button exit; private Rectangle clientArea; private RootHook rootHook; public LoginUI (Hook hook) {rootHook = (RootHook) hook;} / ** * Display login interface * / public void show () {Display.getDefault (). Dispose (); display = new display (); clientarea = display.getClientarea (); shell = new shell (display, swt.title); formyout Layout = new formLayout (); layout.marginheight = 10; layout.marginwidth = 20; shell.setLayout (layout); shell.settext ("User Login"; Name =

New label (shell, swt.none); name.setText ("User Name); Nametext = New Text (Shell, Swt.Single | SWT.BORDER); Pass = New Label (Shell, Swt.none); Pass. Settext ("password"); passtext = new text (shell, swt.single | swt.border); passtext.sechochar ('*'); passtext.settabs (2); bottom = new Composite (shell, swt.none) ; RowLayout rowLayout = new RowLayout (); rowLayout.justify = true; bottom.setLayout (rowLayout); ok = new Button (bottom, SWT.PUSH); ok.setText ( "OK"); ok.addSelectionListener (new SelectionAdapter ( {Public Void WidgetSelected (SelectionEvent Event) {OK ();}}); exit = new button (Bottom, SWT.PUSH); EXIT.SETTEXT ("Cancel"); Exit.AddSerectionListener (New SelectionAdapter () {public void WidgetSelected (SelectionEvent Event) {Cancel ();}}; Formdata Data = New Formdata (); data.top = new Formattachment (15, 0); Name.setLayOutdata (DATA); DATA = New Formdata (); Data.top = New Formattachment (Name, 0, SWT.Center); Data.Left = New Formattachment (Name, 10, SWT. Right); Nametext.setLayOutdata (data); data = new formData (); data.top = new formattachment (Name, 10, SWT.BOTTOM); Pass.setLayOutdata (Data); data = new formData (); data.top = New formattachment (pass, 0, swt.center); data.left = new formattachment (Nametext, 0, Swt.LEFT); passtext.setLayOutdata (data); data = new formData (); data.top =

转载请注明原文地址:https://www.9cbs.com/read-91852.html

New Post(0)