2013-04-23 4 views
0

특정 확인란을 선택했을 때 나타나는 Eclipse에 복합체를 추가하고 싶습니다. 복합 요소는 WARNING_ICON과 텍스트가있는 레이블의 두 부분으로 구성됩니다.SWT 라벨로 ICON_WARNING을 정렬하십시오.

나는 레이아웃을 아주 좋아 보이지 않는다. 이미지와 레이블을 나란히 표시하고 싶다.

 final Composite warningComposite = new Composite(parent, SWT.NONE); 
     warningComposite.setLayout(new GridLayout(2, false)); 
     warningComposite.setLayoutData(new GridData(0, 0, true, false)); 

     Label l = SWTUtilities.createLabel(composite, "", -1, -1, 1, GridData.BEGINNING); 
     final Image img = PlatformUI.getWorkbench().getDisplay().getSystemImage(SWT.ICON_WARNING); 
     l.setImage(img); 
     l.setLayoutData(new GridData()); 

     l = SWTUtilities.createLabel(composite, "Wizards Gone Wild", -1, -1, 1, GridData.END); 

그리고 SWTUtilities.createLabel 방법 :이

public static Label createLabel(final Composite parent, final String label, final int width, final int indent, final int span, final int style) { 
     Assert.isNotNull(parent); 
     Assert.isNotNull(label); 
     final Label control = new Label(parent, SWT.WRAP); 
     control.setText(label); 
     if (width > 0 || indent > 0 || span > 0) { 
      final GridData data = new GridData(style); 
      if (width > 0) 
       data.widthHint = width; 
      if (indent > 0) 
       data.verticalIndent = indent; 
      if (span > 1) 
       data.horizontalSpan = span; 
      control.setLayoutData(data); 
     } 
     return control; 
    } 

답변

1

당신이 이동 :

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

    Label image = new Label(shell, SWT.NONE); 
    image.setImage(d.getSystemImage(SWT.ICON_WARNING)); 
    image.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    Label text = new Label(shell, SWT.NONE); 
    text.setText("SOME TEXT HERE"); 
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); 


    shell.pack(); 
    shell.open(); 
    while (!shell.isDisposed()) 
     while (!d.readAndDispatch()) 
      d.sleep(); 
} 

는 다음과 같습니다 : 여기 내 코드의 섹션입니다

enter image description here


설명 : SWT는 Label 내의 텍스트의 수직 정렬을 지원하지 않습니다 (모든 OS에서 지원하지 않기 때문에). 해결책은 레이블 안의 텍스트가 아닌 상위의 중앙에 레이블을 정렬하는 것입니다.

관련 문제