2014-10-31 19 views
2

我有一個複合(容器)是在另一個複合(對話框區域)。該容器包含一些UI元素。我怎樣才能讓對話框的大小變大或使其可調整大小。這裏是我的代碼可重新調整對話框在Java SWT

protected Control createDialogArea(Composite parent) { 
    setMessage("Enter user information and press OK"); 
    setTitle("User Information"); 
    Composite area = (Composite) super.createDialogArea(parent); 
    Composite container = new Composite(area, SWT.NONE); 
    container.setLayout(new GridLayout(2, false)); 
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 

    Label lblUserName = new Label(container, SWT.NONE); 
    lblUserName.setText("User name"); 

    txtUsername = new Text(container, SWT.BORDER); 
    txtUsername.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); 
    txtUsername.setEditable(newUser); 
    txtUsername.setText(name); 

    return area; 
} 

回答

7

爲了使JFace的對話框可調整大小添加替代的isResizable方法:

@Override 
protected boolean isResizable() { 
    return true; 
} 

爲了使對話框較大時,它會打開,你可以在設置的寬度或高度提示佈局。例如:

GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); 
data.widthHint = convertWidthInCharsToPixels(75); 
txtUsername.setLayoutData(data); 

或可以覆蓋getInitialSize(),例如這個碼被留出空間用於多個字符在水平方向(75個字符)和垂直(20行):

@Override 
protected Point getInitialSize() { 
    final Point size = super.getInitialSize(); 

    size.x = convertWidthInCharsToPixels(75); 

    size.y += convertHeightInCharsToPixels(20); 

    return size; 
}