How do i make the program finish the JDialog before continuing?
Hey! I have this line of code....
for (int i = 0; i < uselessArray.size(); i++){
uselessChoice =new UselessDialog(uselessArray.get(i));
}
My problem is that 4 instances are being created of the UselessDialog. But I want the user to close the first one before the second uselessDialog is created. How do I do this?
Secondly, I want the JDialog to be modal, i.e. the user should not be able to go to any other jframes or jdialogs...so I've added this to the UselessDialog constructor...
setModalityType(ModalityType.APPLICATION_MODAL);
but it doesn't work, as I can go to the main jFrame...
Any help greatly appreciated with these relatively new things to me!
check out JDialog api here:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JDialog.html
and tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html#eg
If you look in the Constructor Summary, you will find several constructors where you can tell java that the dialog is modal. It's as simple as passing a true boolean argument in the correct parameter position. Then in your for loop, show your dialog with setVisible(true).
Hope this helps.
Those constructors are interesting...but how do I implement it in my program? I am extending the JDialog...
class UselessDialog extends JDialog {
UselessDialog(MyType obj) {
so does this mean I must make the same constructor the the JDialogs have? How do I do that?
Also, instead of setVisible, can't I use synchronization? I don't know how it works, but wouldn't it be helpful here?
> Those constructors are interesting...but how do I
> implement it in my program? I am extending the JDialog...
>class UselessDialog extends JDialog {
>
> UselessDialog(MyType obj) {
> s this mean I must make the same constructor the the
> JDialogs have? How do I do that?
>
> Also, instead of setVisible, can't I use synchronization? I don't know
> how it works, but wouldn't it be helpful here?
Just because you don't explicity call a superclass constructor, the
default superclass constructor will be invoked which creates a
non modal dialog not in front of any specified window, frame or other
dialog. (read the JDialog API documentation for that).
Alter your class' constructor so you can pass it a JFrame and call the
superclass constructor like this:
super(frame, true);
The 'true' flag indicates that the dialog should be modal.
kind regards,
Jos
JosAHa at 2007-7-28 18:48:34 >

Thanks! OK, but that leads me to another problem, how do i get the variable name of my main JFrame if I don't have a variable for it? lol
It is created like this (which i think was the default code for netbeans):
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
});
So is there any getParent, getrootpane or something that will work in the super call of the uselessDialog?
> Thanks! OK, but that leads me to another problem, how
> do i get the variable name of my main JFrame if I
> don't have a variable for it? lol
>
> So is there any getParent, getrootpane or something
> that will work in the super call of the uselessDialog?
could you use this, or how about null?
I have, it didn't work. this = cannot reference this before supertype constructor has been called
null = reference to JDialog is ambigious both methods ... ... match
anyone have any ideas?
> I have, it didn't work. this = cannot reference this
> before supertype constructor has been called
> null = reference to JDialog is ambigious both methods
> ... ... match
>
> anyone have any ideas?
You can pass a (Window)null value as the first parameter (read the API docs).
The JDialog isn't owned then but there are a few nasty consequences
when you (de)iconize your JFrame: the dialog can show up behind your
JFrame.
kind regards,
Jos
JosAHa at 2007-7-28 18:48:34 >
