2014-01-28 13 views
5

Ich brauche eine Schaltfläche, die ständig in der unteren linken Ecke meines JFace-Dialogfelds platziert wird, auch wenn die Größe des Dialogfelds geändert wird.So fügen Sie eine neue Schaltfläche zur Schaltflächenleiste des JFace-Dialogfelds hinzu

I außer Kraft gesetzt haben die createButtonsForButtonBar()

protected void createButtonsForButtonBar(Composite parent) 
{ 
    sampleButton = createButton(parent, IDialogConstants.NO_ID, "Sample", true); 
    createButton(parent, IDialogConstants.OK_ID,"OK", false); 
    createButton(parent, IDialogConstants.CANCEL_ID,"Close", false); 
} 

Ich möchte die Probe Schaltfläche am unteren Rand platziert werden links durch Leerzeichen gefolgt und dann ok, abzubrechen.

Wie erreiche ich das?

Antwort

6

Dies ist die Art und Weise der Eclipse-Dialog tut dies:

protected void createButtonsForButtonBar(Composite parent) 
{ 
    // Change parent layout data to fill the whole bar 
    parent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 

    sampleButton = createButton(parent, IDialogConstants.NO_ID, "Sample", true); 

    // Create a spacer label 
    Label spacer = new Label(parent, SWT.NONE); 
    spacer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 

    // Update layout of the parent composite to count the spacer 
    GridLayout layout = (GridLayout)parent.getLayout(); 
    layout.numColumns++; 
    layout.makeColumnsEqualWidth = false; 

    createButton(parent, IDialogConstants.OK_ID,"OK", false); 
    createButton(parent, IDialogConstants.CANCEL_ID,"Close", false); 
}