Article View: borland.public.jbuilder.java.swing
Article #8821Re: Create a Dialog from Design UI?
From: Paul Furbacher [TeamB]
Date: Fri, 14 Jul 2000 00:00
Date: Fri, 14 Jul 2000 00:00
53 lines
3302 bytes
3302 bytes
Tom Dorgan wrote: > Im a newbie to the JBuilder environment (it's great!) as well as to Swing, > so this may be a dumb question. > > I have created a Frame that allows field editing and it works well. I have > placed a button on the form that, when clicked, should pop up what I believe > should be a Dialog(or should it be a new frame?) which allows the entry of > several fields of data. I have several questions on how to accomplish this: > 1) How do I layout my dialog in the environment? The dialog option seems > always to be grayed out. Do I create a new frame,panel, etc. and stuff to it > or what? (Sorry for the vagueness - Im just not clear on this). Are you saying that when you go to "New" and try to pick the Dialog wizard, it's disabled? If so, I don't know that symptom. > 2) I am currently believing that the environment doesn't let you "attach" > Dialogs to buttons, so I figure I will need to add code in the Button click > event to construct and show the dialog. Is this correct? Yes, you'll have to add code. Just double click on the button in the Designer. That will create the required "actionPerformed()" handler. Instantiate your dialog class (if not already done), pack() it, and then show it. You may have to bring it to the front with "myDialog.toFront()". Depending upon your requirements, you may want to set the dialog to be modal -- but not necessarily. > 3) What is a clean, accepted method of communicating the collected data back > to the main frame? I think there may be some examples that come with JBuilder which may show how to do this -- not sure though. Just think in terms of "MyDialog.setData()" and "MyDialog.getData()", and the fact that your calling frame keeps a reference to the dialog. After the user has dismissed it, your frame just asks the still extant dialog (just not visible) about it's data. Also, provide a "getCloseStatus()" method in the dialog class which you call to find out whether you really need to take any action (e.g., the user could have pressed "Cancel" and you don't do anything). Also, if your dialog isn't modal, you have to let the owner know that the user closed it, or hit an "Apply" button. You want to register the owning frame as a listener to those events in the dialog upon which the owner should take action. In the case of closing, the owner can listen for a window closing event. The dialog class should process its own window closing event and fire off messages to the registered listeners. Something similar would be done with an "Apply" button, but in this case, you'd perhaps create a special event and event listener pair of classes to handle that. Paul Furbacher (TeamB)
Technical Details
Message-ID:
<396F6CBC.41F8E8F5@home.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<396df77a@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,433b77a33d068963 X-Google-Attributes: gid111d45,public From: "Paul Furbacher [TeamB]" <pnf@home.com> Subject: Re: Create a Dialog from Design UI? Date: 2000/07/14 Message-ID: <396F6CBC.41F8E8F5@home.com> X-Deja-AN: 646447696 Content-Transfer-Encoding: 7bit References: <396df77a@dnews> X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii Organization: Reverse Alchemy, Inc. Mime-Version: 1.0 Reply-To: pnf@home.com Newsgroups: borland.public.jbuilder.java.swing