harishtps
harishtps

Reputation: 1439

RadioButtons in JDialog in Swing?

I need to display a dialog box which contains radio buttons; and when I select the appropriate radio button, the dialog box should disappear?

Upvotes: 0

Views: 4676

Answers (3)

Eugene Ryzhikov
Eugene Ryzhikov

Reputation: 17359

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.

alt text

Radio buttons are possible but not a better solution from usability point of view.

alt text

Upvotes: 5

Avrom
Avrom

Reputation: 5027

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.

Upvotes: 1

trashgod
trashgod

Reputation: 205785

In your radio button listener, use setVisible(false), as discussed in the articles How to Use Radio Buttons and Creating and Showing Simple Dialogs.

Upvotes: 2

Related Questions