f



How to create custom dialogs?

Hi,

Sorry if this such a simple question, but I've googled and looked around
Sun's tutorials but I can't find how to make custom dialogs? JOptionPane is
too simple - I want a dialog box where I can enter 3 or 4 text fields with
an OK and Cancel button.

I can't believe there aren't any examples I can start from, so I think I'm
using the wrong keywords - I thought 'java custom dialog' would be good
enough!. Any pointers here will be gratefully appreciated!


-- 
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

0
Steve
3/19/2006 9:27:32 AM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

7 Replies
518 Views

Similar Articles

[PageSpeed] 20

Steve,

Check out this custom dialog creation tutorial:

http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

Aleksey

0
Aleksey
3/19/2006 9:42:10 AM
Or this one :
http://javalessons.com/cgi-bin/fun/java-tutorials-main.cgi?ses=ao789&code=odl&sub=gui
(Got it Googled with your keywords btw)

0
Paul
3/19/2006 10:26:47 AM
So did I. The keywords: "custom dialogs java". ;)

0
Aleksey
3/19/2006 10:57:33 AM
On 19/3/06 09:42, in article
1142761329.978309.266470@u72g2000cwu.googlegroups.com, "Aleksey Gureev"
<spyromus@gmail.com> wrote:

> Steve,
> 
> Check out this custom dialog creation tutorial:
> 
> http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
> 
> Aleksey
> 

Thanks Aleksey (and Paul)

Ok, I got it. There was a lot of irrelevant information I had to sift
through to get just what I wanted. The important bit was to construct my
JDialog as modal, then it's just a matter of setVisible(true).

I was looking for something like a simple showModal call which would return
a result to indicate if I pressed OK or Cancel. I can see now that's just
too specific for Swing - it's up to me to handle OK or Cancel then do
setVisible(false), I then write my own getResult method or something similar
to find out what happened. Am I on the right lines here?


(Sorry if this seems obvious to everyone; I'm new to Java!)


-- 
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

0
Steve
3/19/2006 11:51:23 AM
Yes, in case when you extend JDialog and create your own contents, you
have to take care of any buttons and then fetch the result with some
getResult() method. There's setModal(boolean) method to make the dialog
modal, so that it will return control only when the dialog gets
disposed. Everything else is pretty simple -- you get the content pane
(getContentPane()) in constructor, set some layout to it and add your
components (fields, labels, buttons). The last thing to do is to call
pack() to compact the dialog and position it on the screen. Now it's
ready for setVisible(true).

Aleksey

0
Aleksey
3/19/2006 1:45:36 PM
On 19/3/06 13:45, in article
1142775936.940352.220340@z34g2000cwc.googlegroups.com, "Aleksey Gureev"
<spyromus@gmail.com> wrote:

> Yes, in case when you extend JDialog and create your own contents, you
> have to take care of any buttons and then fetch the result with some
> getResult() method. There's setModal(boolean) method to make the dialog
> modal, so that it will return control only when the dialog gets
> disposed. Everything else is pretty simple -- you get the content pane
> (getContentPane()) in constructor, set some layout to it and add your
> components (fields, labels, buttons). The last thing to do is to call
> pack() to compact the dialog and position it on the screen. Now it's
> ready for setVisible(true).
> 
> Aleksey
> 

Thank you Aleksey.

It was your concise description above I was hoping to find somewhere! :-)

Cheers.

-- 
Regards,
Steve

"...which means he created the heaven and the earth... in the DARK! How good
is that?"

0
Steve
3/19/2006 1:56:07 PM
"Steve" <root@127.0.0.1> wrote in message 
news:C042F63A.133571%root@127.0.0.1...
> On 19/3/06 09:42, in article
> 1142761329.978309.266470@u72g2000cwu.googlegroups.com, "Aleksey Gureev"
> <spyromus@gmail.com> wrote:
>
>> Steve,
>>
>> Check out this custom dialog creation tutorial:
>>
>> http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
>>
>> Aleksey
>>
>
> Thanks Aleksey (and Paul)
>
> Ok, I got it. There was a lot of irrelevant information I had to sift
> through to get just what I wanted. The important bit was to construct my
> JDialog as modal, then it's just a matter of setVisible(true).
>
> I was looking for something like a simple showModal call which would 
> return
> a result to indicate if I pressed OK or Cancel. I can see now that's just
> too specific for Swing - it's up to me to handle OK or Cancel then do
> setVisible(false), I then write my own getResult method or something 
> similar
> to find out what happened. Am I on the right lines here?
>
>
> (Sorry if this seems obvious to everyone; I'm new to Java!)

    If you only have an OK or Cancel button, you can use a pre-written 
Dialog, and then you'd just call a method whose return value indicates what 
button was pressed, as you described.

    Read 
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JOptionPane.html and in 
particular, 
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JOptionPane.html#showConfirmDialog(java.awt.Component,%20java.lang.Object)

    - Oliver 

0
Oliver
3/23/2006 6:54:09 PM
Reply: