2012-10-03 1 views
0

SWT에서 일하고 있고 원하는 방식대로 문제를 배치하고 있습니다. 본질적으로 나는 그것의 너비를 가지고 싶은 객체가 Text인데,이 객체의 위치는 컴포넌트의 너비입니다. FillLayout을 사용할 수 있지만 그 아래에있는 버튼도 커지므로 원하는 것은 아닙니다. 여기
enter image description hereSWT 텍스트 구성 요소가 가로로 채워지지 않습니다.

내가 재현 사용하여 오전 테스트 코드이며, 문제 해결을 시도 :

import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.GridData; 
import org.eclipse.swt.layout.GridLayout; 
import org.eclipse.swt.widgets.Button; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.widgets.Text; 
import org.eclipse.wb.swt.SWTResourceManager; 


public class Test { 

    public static void main(String[] args) { 
     Display display = new Display(); 
     Shell shell = new Shell(display); 

     shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); 
     //setup the layout manager  
     GridLayout layout = new GridLayout(1, false); 
     layout.horizontalSpacing = 0; 
     layout.marginHeight = 0; 
     layout.verticalSpacing = 5; 
     layout.marginWidth = 0; 
     layout.marginBottom = 20; 
     layout.marginTop = 5;  

     shell.setLayout(layout); 

     //create the text field 
     Text inputField = new Text(shell, SWT.BORDER); 
     GridData data = new GridData(); 
     data.horizontalAlignment = GridData.FILL; 
     data.grabExcessHorizontalSpace = true; 
     inputField.setData(data); 

     //create the button 
     Button lookup = new Button(shell, SWT.PUSH); 
     lookup.setText("Lookup");  


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

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

내가 가정을 여기

문제를 설명하기 위해 스크린 샷 그냥 inputField에 대한 GridData 개체에서 올바르게 설정하지 않을 것이지만 무엇이든지간에 나는 그것을 분명히 보지 못합니다. , GridData.FILL is not recommended의 사용 대신 SWT.FILL를 사용 : BTW

Text inputField = new Text(shell, SWT.BORDER); 
GridData data = new GridData(); 
data.horizontalAlignment = SWT.FILL; 
data.grabExcessHorizontalSpace = true; 
inputField.setLayoutData(data); 

:

답변

6

당신은 GridData하지 setData() 설정 setLayoutData()을 사용해야합니다.

+0

downvote에 대한 설명은 감사하겠습니다 ... – Baz

관련 문제