Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a selected row statement but it always return the first row. I have a statement fireTableDataChanged() when I delete or add a row and I don't now cause is that or not.
My code here
Selected row statement:
public void mouseClicked(MouseEvent e)
{
selectedrow = table.getSelectedRow();
}

When I delete or insert one row, I run this statement:
model.fireTableDataChanged();

The first time I try it returns correctly row, but any times later, it wrongs, it always return the first row, it mean index = 0, I try print it and I confirm that true, always 0.
Please help me.

What I have tried:

Please help me fix it. I spend very much my time but nothing happen
Posted
Updated 10-Jan-22 3:13am

This is the second time you have posted this exact question, and nothing has changed in the meantime.
So what is the point of posting the same thing?

All you are staying here is "It don't work", and "I've done nothing to fix it myself".
That's not helpful.

The problem is almost certainly down to the order in which things happen: MouseClick probably happens before the "cell selected" event which means that you can't access the "new" row in that handler.

Start by looking at the control you are using - we have no idea what it is - and seeing what events it supports. Almost certainly, there is a more appropriate one ...
 
Share this answer
 
Comments
Member 15493982 10-Jan-22 8:21am    
I'm sorry about that, but I think if I post a new, I can have more attention.
So sorry.
And I don't know. I'm using MouseListener to do select row.
Dave Kreskowiak 10-Jan-22 8:30am    
"more attention"? It's quite the opposite. The more you post the same question, the more you're going to get ignored, not just here on CP, but on all forums on all sites.
Member 15493982 10-Jan-22 8:42am    
Sorry :((( Next time I will learn from my experience
OriginalGriff 10-Jan-22 9:06am    
As Dave said, it's counterproductive.
There is a technical term for it: "Bumping" - it means "trying to get my post to the top of the queue so everybody sees it", and it's a very rude thing to do.
Your post is important to you, but everybody else has what they think is important as well - so if you "bump" your question, why shouldn't they? And very quickly you get everybody bumping every question and nobody gets to see anything, so nobody gets an answer to anything.

So ... do it again, and you're going to come over as a troll - and that's not something you want at all.
Most likely because you are using the wrong event. See AbstractTableModel (Java Platform SE 7 )[^]. which lists the different events that are generated when adding or deleting rows.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900