문제

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[])

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:

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top