tags:

views:

479

answers:

2

Hi all,

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?

+1  A: 
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.

Bombe
A: 

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.

camickr