1

I got a Main class and another Class which extends a jFrame, which holds directly a jTable in it. I kinda want to stop the code from executing until something happens (= the User presses Enter). I then want to get the values of the selected row from the table which I am holding in my other class MyJFrame. As for now, I am trying to achieve this about like that:

ArrayList<String[]> result = new ArrayList<String[]>();
String[ ] columns = new String[] {"h1", "h2", "h3" };

result.add(new String[]{ "some", "test", "values" });
result.add(new String[]{ "some", "test", "values" });

ArrayListTableModel model = new ArrayListTableModel(result, columns);

//waiting for enter...

MyJFrame frame = new MyJFrame(model);
int row = frame.getActiveRow();
selectedData = result.get(row);

PS: I hope you understand my problem, I had some trouble explaining it...

Pascal Weber
  • 557
  • 3
  • 11
  • 19
  • it is called `Listeners` check which listeners you can add to `JTable` – Nikolay Kuznetsov Dec 10 '12 at 15:18
  • yeaaah.. i also solved it with them, the problem is just that the other code after "waiting for enter" already gets executed and i am having problems to avoid this.. – Pascal Weber Dec 10 '12 at 15:21
  • @NikolayKuznetsov changed the subject. hope it's more clear now. – Pascal Weber Dec 10 '12 at 15:22
  • so execute that code in Listener handler – Nikolay Kuznetsov Dec 10 '12 at 15:23
  • @NikolayKuznetsov yeah but i will need this code any further in my main class after then.. – Pascal Weber Dec 10 '12 at 15:31
  • I don't understand. Please, post SSCCE and more explanation on what you are trying to achieve and what is the problem. – Nikolay Kuznetsov Dec 10 '12 at 15:32
  • 1
    1) *"..extends a jFrame, ..I then want to get the values of the selected row from the table which I am holding in my other class MyJFrame"* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) One of those frames should probably be a modal dialog to solve the immediate problem. 2) Don't extend frame, just use an instance. 3) For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Dec 10 '12 at 15:37

1 Answers1

1

..extends a jFrame, ..I then want to get the values of the selected row from the table which I am holding in my other class MyJFrame..

See The Use of Multiple JFrames, Good/Bad Practice? One of those frames should probably be a modal dialog to solve the immediate problem. The dialog will 'pause' the program while open.

For an example of 'waiting for reply', see this answer.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • aah you are my hero! I hard a hard time to explain but cool that someone exactly could help me anyways. I try to post better questions hopefully next time. Thank you, sir! – Pascal Weber Dec 10 '12 at 15:45
  • Glad you got it sorted. I suspected I knew the answer after seeing *"other class MyJFrame"*, being familiar with that problem. ;) – Andrew Thompson Dec 10 '12 at 15:50
  • hah! yea that's another point.. i knew it it's kinda messy, just didn't know where I was doing bad practice. I'd say: 2 Problems solved once :) – Pascal Weber Dec 10 '12 at 16:03