Click to See Complete Forum and Search --> : JDialog - my brain is cluttered


nanode
12-07-2000, 12:30 PM
I know and make use of JOption panes wherever possible, but my current project requires some more complex dialogs.

My basic needs:

1) a modal window that will stay up until 'ok' or 'cancel' is clicked

2) it will contain a JPanel with various JComponents (comboxes, checkboxes etc)

3) clicking 'ok' will return an object to whomever called this dialog.

I've been trying so many combinations or parents, super(), pack and so on, that I've really lost focus of what I need to do. Every example or tutorial I see does it differently.

I'd like to make a simple base class that does the above and extend that in a handful of dialogs that my app will use.

Is there a simple example, or some docs. that address what I need?

Thanks.

nanode
12-07-2000, 01:18 PM
NEVERMIND

I've consulted the master, Bruce Eckel's book and have solved all but #3.

Dru Lee Parsec
12-07-2000, 02:37 PM
nanode:

Think about how we implemented ButtonDialog back at the evil empire.

As fas as #3 here's a cool way to do it: Check out the PropertyChangeEvent and PropertyChangeListener classes/interfaces.

Essentially you can have your dialog box shout out "I changed this property and here's the object that holds it's new value". Any other object that's registered a listener can "hear" that property change, get the associated object, and do whatever it has to do.

So your two objects don't even have to have an actual "link" between them. One fires an event and the other simply is listening for that event.

nanode
12-07-2000, 06:38 PM
Dru:

Good idea.
I've used property change listeners before with Component Beans. http://www.linuxnewbie.org/ubb/smile.gif

Here's a caveat:

If I'm firing a prop. change event from a Modal dialog, will another class be able to 'listen' while the modal dialog is up?

1) modal dialog builds an object based on user input
2) when 'ok' is clicked on the dialog box, the prop change listener is fired, sending the old and new values.
3) the dialog calls its 'dispose()'
4) the parent (who launched the dialog) is listening for the prop. change, but it never seems to happen.

I have used this same type of notification in a non-modal frame context and it worked. So at least I know what I am doing in that regard.

Thanks so much.

-nanode