Dialog window question

I just created a dialog box with some text and an “OK” button, but wasn’t sure how to have the dialog close when the OK button was clicked.

I ended up calling getParentComponent()->setVisible(false), which works, but I wasn’t sure if there was a better way to do this. Should my component communicate with the dialog window in a more elegant way?

Depends how you’re using it, and how you’re planning on deleting it.

If it’s modal, you could use exitModalState(), but setVisible (false) will do the same thing indirectly.

An unrelated follow-up: is there a way to set a button as the default button, so that if there are two choices (OK,cancel) one is highlighted, so the user knows that button will respond to the return key?

Just use grabKeyboardFocus() on it when the dialog is started, or check out the keyboard focus order stuff in Component.

Hi Jules,

what do you mean when a “dialog is started”? you mean in the costructor? is there is a virtual method which’s called when doalog is shown?

thanks

Well, I guess you could put that in the constructor, as long as the dialog has already been made visible by that point.