• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TableView getting value of one cell

 
Ranch Hand
Posts: 95
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to get the value in a single cell of the tableview.

I copied this code from another forum answer but I don't understand the Item where it is supposed to be the table view type. I tried String but that did not work although I think the cell contents is a String?

Even then how dose this code know which cell I want. I can select the row of the tv but not the single cell.



this is where i have defined the table view and I want the value that is in the Template Code cell of the focused row.

 
Roger Wells
Ranch Hand
Posts: 95
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I got most of it working except one item and that is the col. If I click on the column in the tableView it gives me the correct text from that column.

How do I make this code always select column 2 no matter which col i click on? I tried to make col a int col = 2 but it did not like that.

Some how in need this line of code to always be a certain column not the one I click on -  TableColumn col = pos.getTableColumn();


 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't said what this code is for (I assume it is a Swing JTable) so I can only give a general answer.

Rather than getting the column from the selection you need to get the TableColumn object for column 2 directly from your table.
 
Roger Wells
Ranch Hand
Posts: 95
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a tableview in javafx


This is the code I think I need to change as it always returns the col for the column I have clicked - but I don't know how to get the specific tableColumn object for TemplateCodeCol. - TableColumn col = pos.getTableColumn();


This is the code used to set up the column I want
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said TableColumn col = pos.getTableColumn();  gets you the selected column whereas you want column 2 so don't use this line of code. You need to find a way of getting a specified column from TableView (I know nothing about JavaFX so can't tell you exactly how) but there is most probably a method called getColumn() or maybe a getColumns() which you can then select the second column from the retuned collection.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll add this thread to the JavaFX forum and maybe someone there can give more specific advice.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure why you need to always return column two, but if you need a TableColumn with that column, I'd try:
 
Roger Wells
Ranch Hand
Posts: 95
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion but I could not get it to work.

Here is the code that I tried. Line # 8 gives an error incompatible types: int can not be converted to String.

If I use the code in line 7 instead it works but I have to click the cell with the mouse.

My reason for always wanting column 2 is that it contains the value that I want to load into the text area show in line 15 and that is
a string I will use for formatting a output string.

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that error is happening on line 10.  Are you sure the column should be 2?  Remember, that's the third column.  If you want the second column, the index should be 1.
 
Roger Wells
Ranch Hand
Posts: 95
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can not get the project to compile because of line 8 as it gives a error incompatible types: int can not be converted to String in NetBeans ide.

Yes I am aware of the counting starting at 0.

Thanks
Roger

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This line:

...is not trying to convert an int to a String, but this line may be doing so:

If you're sure that NetBeans is getting the error on the first line above, then I'm not sure what to do.

Just as an experiment, you could try this:
 
Roger Wells
Ranch Hand
Posts: 95
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I commented out the line (10) and replaced it with the one you suggested I try line (11).
Line (8) still gives the error incompatible types: int can not be converted to String.

If I comment out line (8) and use line (7) the program compiles but still must select the col and
can not get the exact column I want with out mouse clicking it. So it appears that changing line 10 and 11 did
not make any difference in the outcome of the program.

I have attached a snippet of code where I created the column maybe there?




Code used in creating the column maybe it's something here?



Again thanks for you help
Roger
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm out of my depth.  I've never tried to force a TableView to return a certain column.  It goes against what it was designed for.

I still don't understand: don't you have to put the data into the TableView?  If you're putting the data in at a certain column, don't you already know what it is?

It might be a good exercise to create a SSCCE that demonstrates the problem.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey! I was doing same thing today and saw your post. finally i got my solution. I don't know which column you want to take so I am assuming that groupNameCol is it. now you can simply set on mouse clicked

and then in your events, you can do something like

reply
    Bookmark Topic Watch Topic
  • New Topic