I need to d开发者_StackOverflowisplay a dialog box which contains radio buttons; and when I select the appropriate radio button, the dialog box should disappear?
Try to use TaskDialog framework. It helps to accomplish just the things you ask for in few lines of code. For your case using Command Links is the best solution.
Radio buttons are possible but not a better solution from usability point of view.
In your radio button listener, use setVisible(false)
, as discussed in the articles How to Use Radio Buttons and Creating and Showing Simple Dialogs.
I agree with the others that having a "dialog disappear" on radio button click is not a very good UI design. Users generally expect that a "dialog disappears" when they select a button at the bottom (e.g. OK, Cancel, Yes, No, etc.).
In any event, if I am to assume that by "dialog disappears" you mean the window closes, then the way to do that is to call dispose
on the dialog.
Also, you may want to consider using JOptionPane
.
精彩评论