Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:55:42+00:00 2026-05-24T12:55:42+00:00

I have two Jframes where frame1 has some text fields and when a button

  • 0

I have two Jframes where frame1 has some text fields and when a button on frame1 is clicked, I open another JFrame which contains a search box and a JTable containing search results.

When I click on a result row on JTable, I want that particular values to be reflected in the frame1 text fields.

I tried passing the JFrame1’s object as a parameter but I have no clear idea on how to achieve this.
Any help would be highly appreciated.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:55:43+00:00Added an answer on May 24, 2026 at 12:55 pm

    First of all, your program design seems a bit off, as if you are using a JFrame for one of your windows where you should in fact be using a JDialog since it sounds as if one window should be dependent upon the other.

    But regardless, you pass references of GUI objects the same as you would standard non-GUI Java code. If one window opens the other (the second often being the dialog), then the first window usually already holds a reference to the second window and can call methods off of it. The key often is when to have the first window call the second’s methods to get its state. If the second is a modal dialog, then the when is easy — immediately after the dialog returns which will be in the code immediately after you set the second dialog visible. If it is not a modal dialog, then you probably want to use a listener of some sort to know when to extract the information.

    Having said this, the details will all depend on your program structure, and you’ll need to tell us more about this if you want more specific help.

    For a simple example that has one window open another, allows the user to enter text into the dialog windows JTextField, and then places the text in the first window’s JTextField, please have a look at this:

    import java.awt.Window;
    import java.awt.Dialog.ModalityType;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.*;
    
    public class WindowCommunication {
    
       private static void createAndShowUI() {
          JFrame frame = new JFrame("WindowCommunication");
          frame.getContentPane().add(new MyFramePanel());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
       }
    
       // let's be sure to start Swing on the Swing event thread
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    class MyFramePanel extends JPanel {
       private JTextField field = new JTextField(10);
       private JButton openDialogeBtn = new JButton("Open Dialog");
    
       // here my main gui has a reference to the JDialog and to the
       // MyDialogPanel which is displayed in the JDialog
       private MyDialogPanel dialogPanel = new MyDialogPanel();
       private JDialog dialog;
    
       public MyFramePanel() {
          openDialogeBtn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                openTableAction();
             }
          });
          field.setEditable(false);
          field.setFocusable(false);
    
          add(field);
          add(openDialogeBtn);
       }
    
       private void openTableAction() {
          // lazy creation of the JDialog
          if (dialog == null) {
             Window win = SwingUtilities.getWindowAncestor(this);
             if (win != null) {
                dialog = new JDialog(win, "My Dialog",
                         ModalityType.APPLICATION_MODAL);
                dialog.getContentPane().add(dialogPanel);
                dialog.pack();
                dialog.setLocationRelativeTo(null);
             }
          }
          dialog.setVisible(true); // here the modal dialog takes over
    
          // this line starts *after* the modal dialog has been disposed
          // **** here's the key where I get the String from JTextField in the GUI held
          // by the JDialog and put it into this GUI's JTextField.
          field.setText(dialogPanel.getFieldText());
       }
    }
    
    class MyDialogPanel extends JPanel {
       private JTextField field = new JTextField(10);
       private JButton okButton = new JButton("OK");
    
       public MyDialogPanel() {
          okButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                okButtonAction();
             }
          });
          add(field);
          add(okButton);
       }
    
       // to allow outside classes to get the text held by the JTextField
       public String getFieldText() {
          return field.getText();
       }
    
       // This button's action is simply to dispose of the JDialog.
       private void okButtonAction() {
          // win is here the JDialog that holds this JPanel, but it could be a JFrame or 
          // any other top-level container that is holding this JPanel
          Window win = SwingUtilities.getWindowAncestor(this);
          if (win != null) {
             win.dispose();
          }
       }
    }
    

    You’d do a very similar technique to get information out of a JTable.

    And again, if this information doesn’t help you, then please tell us more about your program including showing us some of your code. The best code to show is a small compilable example, an SSCCE similar to what I’ve posted above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a top level container (JFrame) that contains two JPanels. One of the
I Have two files. One extends JFrame, and another Extends JPanel. Whenever I change
I have two radio buttons in frame1. On click on enable radio button, it
In my program I have two JFrame instances. When I click next button I
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two elements: <input a> <input b onclick=...> When b is clicked, I
I have two identical tables and need to copy rows from table to another.
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
I have two insert statements, almost exactly the same, which run in two different
I have a window that has two layers: a static background and a foreground

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.