Results 1 to 4 of 4
  1. #1
    tarami is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default Passing data from one JFrame to another JFrame

    Hi, I'm new to Java and completely out of conception how to solve my problem.

    The trouble is that I have two JFrames.

    JFrame1 has a JLabel and a JButton1.
    JFrame2 has a JTextField and a JButton2

    The interaction between the frames is as following:

    When the JButton1 on JFrame1 is pressed the JFrame2 shows up. User enters some text in the JTextFields and then clicks the JButton2 on JFrame2. Then the JFrame2 disappears and the Label on JFrame1 is set with the text that has been entered in JTextField that was on JFrame2.

    How can I do that?

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    First of all JFrame2 should be a JDialog as it is a child of JFrame1. The JDialog has an owner, which in your case is JFrame1. So when closing the JDialog you can pass information.
    see this tutorial: How to Make Dialogs (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)

  3. #3
    tarami is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    Thank u for the answer.

    What if I want to design a more sofisticated dialog window for, say, a personal details questionnaire with various visual components such as JFormattedTextFields, JSpinners, JComboBoxes?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by tarami View Post
    What if I want to design a more sofisticated dialog window for, say, a personal details questionnaire with various visual components such as JFormattedTextFields, JSpinners, JComboBoxes?
    We'd probably encourage you to "go for it." There's nothing about a JDialog that would stop you from doing this as it can accept just as much complexity in its content pane as a JFrame.

Similar Threads

  1. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  2. Returning data from a JFrame/JDialog?!
    By Joe2003 in forum AWT / Swing
    Replies: 6
    Last Post: 01-08-2009, 12:14 AM
  3. help in JFrame
    By kirtesh4u in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2008, 12:26 AM
  4. jframe
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-15-2008, 10:03 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
  •