2012-02-12 15 views
6

行レイアウトで作成された要素の順序を変更する方法はありますか? 最初に表示された要素に表示します。たとえば 私が作成する最後の要素になります最初の要素となりますことを意味 element4要素3要素2要素1RowLayout SWTの要素の順序を変更するJava

ようなレイアウトを見たい要素2要素3、element4

、その後、要素1を作成した場合シェルに表示されます。

行レイアウトを使用して簡単に操作できますか?

次の例を表示するように変更します。 Button99 Button98 Button97 Button96 Button95 Button94 ............................。

import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.RowLayout; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 

public class TestExample 
{ 
    public static void main(String[] args) 
    { 
     Display display = Display.getDefault(); 
     Shell shell = new Shell(display); 
     RowLayout rowLayout = new RowLayout(); 

     shell.setLayout(rowLayout); 

     for (int i=0;i<100;i++) 
     { 
      Button b1 = new Button(shell, SWT.PUSH); 
      b1.setText("Button"+i); 

     } 
     shell.open(); 
     while (!display.isDisposed()) 
     { 
      if (!display.readAndDispatch()) 
      { 
       display.sleep(); 
      } 
     } 
    } 
} 

ありがとうございました。

答えて

0

RowLayoutの要素が逆の順序で配置されるように設定するプロパティはないようです。したがって、配列内の要素を逆にしてループ内に追加したり、この特定の例では、forループの開始条件と終了条件を変更するだけで、Button99 Button98 ...のようになります。D

5

FillLayout,RowLayoutおよびGridLayoutは、コントロールin order to determine the ordering of the controlsのzオーダーを使用します。 (これらの3つのレイアウトでは、コントロールが視覚的に重なり合うことはできません。

デフォルトのzオーダーは作成に基づいているため、デフォルトではそれらを追加した順序になりますその親に

Control.moveAbove()Control.moveBelow()メソッドを使用して、zオーダーを変更することができます(したがって、ウィジェットが描画される順序を変更することができます)。

+0

返信いただきありがとうございます。 – user1205079

0

あなたはSWTのレイアウトのいずれかを使用する場合は、:

すでに:item01、item02、item03 item02前item04挿入します 1. item04 2. item04.moveAbove(item02)

Display display = new Display(); 
Shell shell = new Shell(display); 
shell.setSize(640, 480); 

shell.setLayout(new FillLayout()); 

final Composite itemComposite = new Composite(shell, SWT.NONE); 
itemComposite.setLayout(new RowLayout()); 
Label item01 = new Label(itemComposite, SWT.NONE); 
item01.setText("item01"); 
final Label item02 = new Label(itemComposite, SWT.NONE); 
item02.setText("item02"); 
Label item03 = new Label(itemComposite, SWT.NONE); 
item03.setText("item03"); 

Composite buttonComposite = new Composite(shell, SWT.NONE); 
buttonComposite.setLayout(new GridLayout()); 
Button insertItem = new Button(buttonComposite, SWT.NONE); 
insertItem.setText("Insert"); 
insertItem.addListener(SWT.Selection, new Listener() { 
    public void handleEvent(Event arg0) { 
    Label item04 = new Label(itemComposite, SWT.NONE); 
    item04.setText("item04"); 
    item04.moveAbove(item02); 
    itemComposite.layout(); 
} 
}); 

shell.open(); 
while (!shell.isDisposed()) { 
    if (!display.readAndDispatch()) 
    display.sleep(); 
} 
display.dispose(); 
を作成
関連する問題