Results 1 to 7 of 7
  1. #1
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Exclamation Passing data from one JFrame to another JFrame. - need help.

    My main JFrame will open a second JFrame that has serveral input fields to gather user input and store that information in a String. Once a confirm button has been pressed I need to send that newly created String variable to the main JFrame where I can then use it for other things.

    How do you send the newly created string to the main JFrame once the button is clicked?

    I've tried creating a method inside the second JFrame to call for that particular String but I am not quite sure how I make the main JFrame wait until the confirm button on the second JFrame has been hit before I call that method.

    Any suggestions?

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Unsub View Post
    My main JFrame will open a second JFrame that has serveral input fields to gather user input and store that information in a String. Once a confirm button has been pressed I need to send that newly created String variable to the main JFrame where I can then use it for other things.

    How do you send the newly created string to the main JFrame once the button is clicked?

    I've tried creating a method inside the second JFrame to call for that particular String but I am not quite sure how I make the main JFrame wait until the confirm button on the second JFrame has been hit before I call that method.

    Any suggestions?
    Wouldn't it be better to use a modal dialog for that second frame? That way the first frame has to wait until the user dismisses the dialog. It'd feel more 'natural' to the user.

    kind regards,

    Jos

  3. #3
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    I've read about that while doing some research but unfortunately JDialog is beyond the scope of material covered in my classes. I also think I may lose marks if I start to venture into material that I dont fully understand or have a full grasp of.

    can I design and code a JDialog just like a JFrame?

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Unsub View Post
    I've read about that while doing some research but unfortunately JDialog is beyond the scope of material covered in my classes. I also think I may lose marks if I start to venture into material that I dont fully understand or have a full grasp of.

    can I design and code a JDialog just like a JFrame?
    Maybe you can disable the first JFrame (or all of its components) while the second JFrame is showing; personally I find that a hack. JDialogs are almost like JFrames except for the fact that they can be modal.

    kind regards,

    Jos

  5. #5
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    update:

    I've been doing some pokin around with the JDialog and I might actually go this route because it's providing me with exactly what I need.

    JosAH can you explain to me what .dispose() does and if I should be using it when I want to hide the window?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Unsub View Post
    update:

    I've been doing some pokin around with the JDialog and I might actually go this route because it's providing me with exactly what I need.

    JosAH can you explain to me what .dispose() does and if I should be using it when I want to hide the window?
    The dispose() method is inherited from the Window class and it releases all the native resources used by the JDialog; when you want to (re)display it again the resources are reallocated again. It depends if you want to reuse your JDialog again after it was shown; if not, dispose() it, otherwise if memory is not a problem just set your JDialog invisible so it (re)display a bit faster later.

    kind regards,

    Jos

  7. #7
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    Thanks Jos,

    Instead of creating another posting I'm just gonna go a head and ask my next question here since its along the same lines as my topic.

    Once I return from the JDialog back to the JFrame, how do I refresh element/components within the JFrame?

    I'm trying to refresh a JList once I've returned back from the JDialog... in this case the JDialog is actually adding elements to teh JList's model.

    I've tried .repaint(), .validate(), .updateUI() and thats with the entire JFrame and the components alone aswell. but no success.

Similar Threads

  1. passing an object from one JDialog to Jframe
    By sinha in forum AWT / Swing
    Replies: 7
    Last Post: 12-16-2009, 04:56 PM
  2. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  3. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  4. Returning data from a JFrame/JDialog?!
    By Joe2003 in forum AWT / Swing
    Replies: 6
    Last Post: 01-08-2009, 12:14 AM
  5. Passing data from one JFrame to another
    By abhiN in forum New To Java
    Replies: 2
    Last Post: 03-28-2008, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •