• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable.getSelectedRow is returning -1  RSS feed

 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subject:


Line of code calling the JTable method



 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So did you actually select any rows?
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:So did you actually select any rows?


I highlighted one row with the mouse and then clicked the button
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your SSCCE that demonstrates the problem.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Post your SSCCE that demonstrates the problem.


I didn't know what SSCCE was until you posted this and I did some research. While doing the SSCCE I removed everything and it worked. So I was able to put everything back and remove either a line or a few lines the run which allowed me to narrow it down to the lines that I remove which will let me get the right results of the selected row. If I remove the two lines below the code works perfectly but I don't have my entire graphical user interface. I am not sure as to why this is part of the code is causing the issues. The way that the gui hierarchy goes is that I have a frame with a tabbed panel attached. Their are three panels attached to the tabbed panel, customer, start and product. The three panels are only related with one another by the tabbed pane. So why would removed the lines of code below cause the issue?



This is my GUI class just so you can get a picture of what I am working with. A lot of code is removed so it is easier to read.


 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Sexton wrote: . . . While doing the SSCCE I removed everything and it worked. So I was able to put everything back and remove either a line or a few lines the run which allowed me to narrow it down . . .
I know precious little about tables, but I do know you have done very well refining your SSCCE
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but I do know you have done very well refining your SSCCE


I have to disagree. The OP has not posted a SSCCE and the code posted will not help solve the problem.

While doing the SSCCE I removed everything and it worked.


That is the point of a SSCCE. To simplify the code and make it easier to debug and understand the concept.

So why would removed the lines of code below cause the issue?


No idea. Did you try just adding an empty panel? Is it the components on those panels that cause problems.

You do know that by default a JTable does not have any row selected? The user must click on the row, unless your code specifically sets the selected index.

Until a proper SSCCE is posted I doubt the question can be answered.
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea. Did you try just adding an empty panel? Is it the components on those panels that cause problems.

You do know that by default a JTable does not have any row selected? The user must click on the row, unless your code specifically sets the selected index.

Until a proper SSCCE is posted I doubt the question can be answered.


If you reread my comment I said that I removed everything which means including the tabbed pane. That was the first thing I did was just to take the jtable and the button and place them on a panel. It worked so I started over by removing pieces of code at a time and running. I repeated this until I found a solution to the problem. The problem was with the start panel and product panel. Well instead of stopping their I should have continued my search but I didn't. Instead I ended up posting here. After reviewing your last comment I went back and started removing components from the start panel and product panel. I solved the problem on my own by doing two SSCCE's according to this article http://sscce.org/

The issue lied with me declaring the JTable as an instance variable instead of a field variable for each inner class. I declared the JTable as an instance variable because it is a few less lines I have to write and reduces redundant code. Why this was the problem I don't know, maybe one of y'all might be able to help that?
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to disagree. The OP has not posted a SSCCE and the code posted will not help solve the problem.




I have to disagree. The OP has not posted a SSCCE and the code posted will not help solve the problem.

I don't disagree according to the article and research I did, I didn't post any code because I thought that I had narrowed it down enough to be solvable but I was incorrect. I did do a SSCCE, not once but twice http://sscce.org/
 
Charles Sexton
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wanted o thank everyone for the help and I have learned a lot.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem on my own by doing two SSCCE's


Good, that is the purpose of the SSCCE, to simplify the problem. The majority of time you will find the problem on your own. But if you don't, then you have simple code to post in the forum.

The issue lied with me declaring the JTable as an instance variable instead of a field variable for each inner class


And there is no way we could have suggested that based on the verbal description of the problem. That is why we need a SSCCE so we can be a second set of eyes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!