2014-02-19 2 views
0

한 줄에 여러 객체를 만듭니다.개체 사이의 간격을 제거하는 방법은 무엇입니까?

나는 개체 내가 할 수있는 방법

사이의 공간을 제어하려면? RowLayout을 변경해야합니까?

public static void main(String[] args) 
{ 
Display display = new Display(); 
final Shell shell = new Shell(display); 
shell.setText("StackOverflow"); 
shell.setLayout(new GridLayout(2, false)); 

Composite myComposite = new Composite(shell, SWT.NONE); 
myComposite.setLayout(new GridLayout(1, false)); 
myComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

Composite deComposite = new Composite(myComposite, SWT.NONE); 
deComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); 

Label createDetailsde = createDetailsde(deComposite); 

shell.pack(); 
shell.open(); 

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

}

private static Label createDetailsde(Composite detailsComposite) 
    { 
    Label linkLabel = new Label(detailsComposite, SWT.NONE); 
    linkLabel.setText("test"); 
    return linkLabel; 

}

답변

3

사용 RowLayout#spacing = 0하는 항목 사이의 간격을 제거합니다. 여기에 몇 가지 예제 코드입니다 (내가 만들기 위해 Label 초 동안 SWT.BORDER 사용은 간격이 더 분명) : 간격

public static void main(String[] args) 
{ 
    Display display = new Display(); 
    final Shell shell = new Shell(display); 
    shell.setText("StackOverflow"); 
    shell.setLayout(new GridLayout(2, false)); 

    Composite myComposite = new Composite(shell, SWT.NONE); 
    myComposite.setLayout(new GridLayout(1, false)); 
    myComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL); 
    rowLayout.spacing = 0; 

    Composite deComposite = new Composite(myComposite, SWT.NONE); 
    deComposite.setLayout(rowLayout); 

    createDetailsde(deComposite); 
    createDetailsde(deComposite); 
    createDetailsde(deComposite); 
    createDetailsde(deComposite); 

    shell.pack(); 
    shell.open(); 

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

} 

private static Label createDetailsde(Composite detailsComposite) 
{ 
    Label linkLabel = new Label(detailsComposite, SWT.BORDER); 
    linkLabel.setText("test"); 
    return linkLabel; 

} 

:

enter image description here

:

enter image description here

간격없이

관련 문제