I have two JFrames in my application. In the first JFrame there is a JTable. When the user clicks the JTable I want to get the clicked row's object then open the second JFrame and fill its data fields with this object's elements.
So how can I transfer objects between JFrames? Can someone give me an example for this?
public void mouseClicked(MouseEvent mouseEvent) {
int row = getClickedRow(mouseEvent); /* dummy code */
Object rowObject = getRowObject(row); /* more dummy code */
JFrame2 jframe2 = ... /* get reference to jframe2 */
jframe2.setRowObject(rowObject);
jframe2.setVisible(true);
}
JFrame2
should probably be extending JFrame
and contain additional stuff that processes the row object in whatever way you see fit.
Generally, an application will only have a single main JFrame. So you should be using a JDialog as a child window, not a JFrame.
Can someone gimme an example for this ?.
Well the steps seems straight forward:
a) add a MouseListener to the table
b) convert the mouse click to a row and/or column
c) get the data from the table
d) create a JDialog using the data as a parameter
So what steps are you having problem with? Post your code showing what you have done.
That is post a Short, Self Contained, Correct (Compilable), Example (SSCCE). The example should use hard coded data, not data from a database because we don't have access to your database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.