JFace/SWT: Change the labels for buttons in InputDialog
Asked Answered
Z

2

8

I want to create an InputDialog with custom labels for the OK/Cancel buttons. I'm using org.eclipse.jface.dialogs.InputDialog.

I tried to override the button creation method:

   @Override
   protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);
    getButton(IDialogConstants.OK_ID).setText(myOkText);
    getButton(IDialogConstants.CANCEL_ID).setText(myCancelText);
   }

and it works, but the buttons are not resized (and the custom text results cropped).

I guess it's too late to set the text here, because the layout manager has already decided the button size and one cannot tell it to recompute... Is that so?

What is the correct way ?

Zwick answered 11/8, 2010 at 15:19 Comment(0)
D
16

try this

 @Override
   protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);

    Button ok = getButton(IDialogConstants.OK_ID);
    ok.setText(myOkText);
    setButtonLayoutData(ok);

    Button cancel = getButton(IDialogConstants.CANCEL_ID);
    cancel.setText(myCancelText);
    setButtonLayoutData(cancel);
 }
Dedradedric answered 13/8, 2010 at 13:51 Comment(1)
I works. I'd missed that setButtonLayoutData method... Thanks!Zwick
U
2

try in this way..

@Override
protected void createButtonsForButtonBar(Composite parent) {

    Button button = createButton(parent,9999, "HEllo", true);
    Button button2 = createButton(parent,9999, "HEllo232323sdsdsdsd", false);

}
Undermine answered 13/8, 2010 at 6:54 Comment(1)
Thanks, but I didnt want to crete new Buttons, but just change the labels of the default predetermined ones (OK/CANCEL).Zwick

© 2022 - 2024 — McMap. All rights reserved.