aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Dialogs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dialogs" Watch "Dialogs" New topic
Author

Dialogs

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i have a dialog that calls another one while pressing a button. I would like that the first dialog is blocked till the second one is opened. How to do?

i have a dialog made with netbean, i have some jLables and a jTextField that even if i change them the name, always have the old name, why??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Antony Amicone wrote:i have a dialog that calls another one while pressing a button. I would like that the first dialog is blocked till the second one is opened. How to do?

Make it modal.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
newbie sorry... can you tell me more?
Jan Hoppmann
Ranch Hand

Joined: Jul 19, 2010
Posts: 147

Try looking here:
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/dialog.html

Oracle has a lot of Java tutorials online, you should take a look at them sometimes, especially if you're a newbie.


Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
Moving to our GUIs forum, where we usually discuss that sort of question.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
ty i read that page, i know that i need to use .setvisible() but a lil problem :P when i calls the second window, i am into the first, so i do secondwindows.setVisible(true) but how can i call the method on the window i already am? i am in that class already
Jan Hoppmann
Ranch Hand

Joined: Jul 19, 2010
Posts: 147

With this.setVisible();. this always references the current object.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Jan Hoppmann wrote:With this.setVisible();. this always references the current object.

was the same thing i tried, but when i call this. it only show me few things, not the setVisible, probably cause i call the other dialog in a button action

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
in your first post
"i have a dialog that calls another one while pressing a button."
then in your 3rd post
"when i calls the second window, i am into the first, so i do secondwindows.setVisible(true) but how can i call the method on the window i already am? i am in that class already"

so, you state you are doing 'something', then you later ask how to do that same 'something'?

smells troll-ish to me.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Michael Dunn wrote:in your first post
"i have a dialog that calls another one while pressing a button."
then in your 3rd post
"when i calls the second window, i am into the first, so i do secondwindows.setVisible(true) but how can i call the method on the window i already am? i am in that class already"

so, you state you are doing 'something', then you later ask how to do that same 'something'?

smells troll-ish to me.


you didnt got what i said :P

i have a dialog FIRSTDIALOG, when i press a button it launch another dialog SECONDDIALOG.
so in the Action of the button i have the call to SECONDDIALOG with mydialog x = new mydialog(); x.setVisible(true);
i need that till this SECONDDIALOG is opened, the FIRSTDIALOG is blocked or hidden, but i am already in the action of a button so if i call this, it doesnt take my FIRSTDIALOG
and doesnt show me this.setVisible(true) in the method options

how solve? i should get the instance of the parent window i think, but dunno how to do that


Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> you didnt got what i said

and I probably still don't get what you said.

"i need that till this SECONDDIALOG is opened, the FIRSTDIALOG is blocked or hidden"

if you want it blocked, you were given the answer in the first reply to your post.

if your problem is hiding the dialog, then
this.setVisible(false);
won't work inside actionPerformed. Depends on how you've structured the listener

if it's an inner class of an extended JDialog e.g. 'class MyDialog extends JDialog'
this.setVisible(false);
would need to be
MyDialog.this.setVisible(false);

if a separate class, you'd need to pass a reference of the dialog to the listener class
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Michael Dunn wrote:
if a separate class, you'd need to pass a reference of the dialog to the listener class

this! thank you micheal i dunno why i didnt think bout that, lool was easy :)

aehm ok dunno how to do looool

the MAIN is in class mainClass, and it create a windows with class DesktWindows

in the DesktopWindows ( that is the one i should hide ) i call the class DeskEvent where i have the actionlistener to the button that open the SecondWindow

so DesktioWindows call a class with actionlistener, that open another window... so i should pass the instance of Desktopwindow to the listener, but how can i get it?

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
helppppppppppppppppp
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
without knowing the class structures, specifically where DeskEvent is created,
all we can do is guess/suggest what to do.

post a simpified version of your program:
MainClass - just a JFrame with a button
DesktopWindows - JDialog with button
SecondWindow = JDialog, doesn't need anything, just a size
DeskEvent - code that opens SecondWindow
include the listener code that opens DesktopWindows

without the above, we don't know how/where DeskEvent is created
i.e. where 'new DeskEvent()' is called
we don't know whether DesktopWindows is a JDialog, or uses a JDialog
etc etc.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Main


FIRST WINDOW


EVENT HANDLER


SECOND WINDOW

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
When Michael was asking you to post a simple version of your program he meant a compilable version. Given that your code as posted doesn't compile, there's no way we can run it, test it or modify it. All I can do is to reiterate what has been posted before: pass a reference of the original dialog or window to the listener which can be done via the listener's constructor or via a setter method -- this has nothing to do with GUI coding but rather is nothing but basic bread and butter Java and nothing more.

Much luck.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I don't have many of the classes you're using (org.desktop's etc),
so all I can do is modify your code to what I think they may be - dialog's etc

you can run this as one .java file, click the button to show second window,
and you'll see firstWindow disappear (hide) at the same time as secondWindow shows.

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125








is it ok now? lol hope i dont need to remove all button
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Michael's post shows the solution to your problem -- you can't go wrong following any suggestions he has to give. You may wish to have a look at this link as it will help you learn how to understand the underpinnings of Swing and thereby create better Swing code: Using Swing Components

Much luck!
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i know is confused that code, i usually write the code but this time i wanted to try netbeans to create a dialog.

i'm gonna reading the page you told me, but is there the answer i need? i dunno how to do that
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Antony Amicone wrote:i know is confused that code, i usually write the code but this time i wanted to try netbeans to create a dialog.

Your netbeans generated code though is too long for us to reasonably go through and modify. This is why we asked you for a simplified version. We don't want to see the whole program but rather just a small compilable program that demonstrates your problem and that we can easily understand and modify.


i'm gonna reading the page you told me, but is there the answer i need? i dunno how to do that

My link is to the Sun Swing tutorials. As I mention above, Michael's posts solve your immediate problem.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
pete stein wrote:
Antony Amicone wrote:i know is confused that code, i usually write the code but this time i wanted to try netbeans to create a dialog.

Your netbeans generated code though is too long for us to reasonably go through and modify. This is why we asked you for a simplified version. We don't want to see the whole program but rather just a small compilable program that demonstrates your problem and that we can easily understand and modify.


i'm gonna reading the page you told me, but is there the answer i need? i dunno how to do that

My link is to the Sun Swing tutorials. As I mention above, Michael's posts solve your immediate problem.


i know, tell me, how should i write the code here? removing all buttons?

i know i have to simply pass the instance to the new dialog, but how??? from the starting dialog?
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
ok solved..... now another question, how can i set the dialog not resizable? i hate the way it resize
Petar Thomas
Ranch Hand

Joined: Oct 11, 2009
Posts: 234


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Check the Javadocs of JDialog and its super class, all the way up the chain until you find a method you like.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i need the instance of the dialog i have there is not getInstance or similar?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Don't you have a reference to it already?
 
Consider Paul's rocket mass heater.
 
subject: Dialogs