开发者

Presenting a JFrame synchronously

I have this main JFrame (call it DrinkChooser) that shows another complex confirmation JFrame (call it ConfirmWin).

The ConfirmWin has only two JButtons, confirm and cancel.

I want to do this:

(in DrinkChooser, assume drinksChoosen is a Drink开发者_JAVA百科[])

public void handleAction(){
int choice = ConfirmWin.showDrinkConfirmation(drinksChoosen);

if(choice == ConfirmWin.CONFIRM)
//Handle confirmation.
else
//handle cancel, do nothing.
}

I want to achieve an effect that is as close as possible to the "JOptionPane effect", which is that the original DrinkChooser gets suspended, and the ConfirmWin returns the choice of the user.

Thanks.


Have a look at the trail How to Make Dialogs.

A Dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window. Most Dialogs present an error message or warning to a user, but Dialogs can present images, directory trees, or just about anything compatible with the main Swing Application that manages them.

For convenience, several Swing component classes can directly instantiate and display dialogs. To create simple, standard dialogs, you use the JOptionPane class.

Here is a possibly related question:

  • Java - How to create a custom dialog box?


Don't forget that the value argument of all JOptionPane.showXXXX methods can be a JComponent. If you pass a component (in your example it might be a JList with a custom renderer), it will be embedded within the dialog and can be used to customize the appearance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜