• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jtable and getselectedRow problem  RSS feed

 
Peter Müller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently writing a small program, where I need to save data into a Defaulttablemodel in a jTable.

I have to save the name, a number and the email-adress.

I added a button which opens a new JFrame and there I need to change the email and/or the name.

My current solution is far from good: No matter which row I select, i can only update the "newest" row (last created).

How can I visualize the values of the selcted row (out.println// or whatever) so I can go further and overwrite these values.


Edit:

My Code when I click on Update:


int zeilenwahl = jTableStudenttab.getSelectedRow();
// System.out.println(jTableStudenttab.getSelectedRow());

if (zeilenwahl != -1) {
this.setVisible(false);
new Bearbeitung().setVisible(true);
} else {
JOptionPane.showMessageDialog(rootPane, "Zum Bearbeiten Zeile auswählen");
}


Here is where the mistake is (probably)

public Bearbeitung() {

initComponents();
jTextFieldvorname.setText(Student.vorname);
jTextFieldnachname.setText(Student.nachname);
matrikelstring = matrikelstring.valueOf(Student.matrikelnummer);
jLabelmatrikelwert.setText(matrikelstring);
jTextFieldemail.setText(Student.email);

}



Thanks for your help
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Student an object or a class? If it's an object, how does it get passed? If it's a class, you're always going to get the same values because the fields (vorname, nachname, etc.) are all static.
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for putting your code in quotes, but even better is putting them in code tags. UseCodeTags (<- click)
 
Peter Müller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Is Student an object or a class? If it's an object, how does it get passed? If it's a class, you're always going to get the same values because the fields (vorname, nachname, etc.) are all static.


It´s a class. So there is no way of doing what I want ( need to ) do?


Thanks for putting your code in quotes, but even better is putting them in code tags. UseCodeTags (<- click)


Ok, I'll do it the next time.

Thank you for your response
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing your exact situation, here's my guess. you should instantiate a Student object based on the selected line. Then pass this object to Bearbeitung().
 
Peter Müller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Without knowing your exact situation, here's my guess. You should instantiate a Student object based on the selected line. Then pass this object to Bearbeitung().


I tried that and failed horribly



Seems to be complete ****



The problem remains that I get only one integer value of the selectedRow



 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instantiating a class (creating an object) should look like this:

<Class> <varName> = new <Class/Subclass>( <optional args> );

So in your case, it would look like:



This is without knowing the Student class, so it's a guess. Also, you don't put the types in when you pass arguments.
 
Peter Müller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you don't put the types in when you pass arguments.


Oh, I forgot to delete them.


It doenst seem to solve my problem sadly.

I want the JFrame, which opens after a click on "change", to have the variables from the selectedRow, but i dont get how.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!