First of all, your program design seems a bit off, as if you were using JFrame for one of your windows, where you really should use JDialog, as it sounds as if one window depended on another.
But regardless of whether you pass references to GUI objects in the same way as standard Java code without a GUI. If one window opens another (the second is often a dialog), then the first window usually already contains a link to the second window and can call methods from it. The key is often when the first window calls the second method to get its state. If the second is a modal dialog, then when it's easy - right after returning the dialog that will be in the code right after you install the second dialog. If this is not a modal dialog, then you probably want to use some kind of listener to find out when to retrieve the information.
Having said that, the details will depend on your program structure, and you will need to tell us more about this if you want more specific help.
For a simple example in which one window opens another, allows the user to enter text in the JTextField dialogs, and then puts the text in the first JTextField, please 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); }
You would make a very similar method to get information from JTable.
And again, if this information does not help you, please tell us more about your program, including showing us some of your code. The best code to show is a small compiled example, SSCCE , similar to what I posted above.
source share