• Post Reply Bookmark Topic Watch Topic
  • New Topic

jtable selection  RSS feed

 
anotida Maditsha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can anyone help me on this. l am writing a java project and l don't know how can l select a row after l successfully found the contents on the jtable. this code do retrieve the contents from sql database and l want it also to highlight the jtable selected row.

 
Omar Rashwan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable is the most complicated component in Swing, for me.
and needs some effort to be mastered. get a look at the TableModel and how it works

for your question ? JTable has this method,
 
anotida Maditsha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Omar Rashwan. let me go through Tablemodel and look especially on the
setRowSelectionInterval(int index0, int index5) method.
 
Rob Camick
Ranch Hand
Posts: 2828
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Selection has nothing to do with the TableModel. The TableModel just stores the data. The JTable displays the data and is responsible for the selection of rows.

In addition to the setRowSelectionInterval(...), JTable also supports addRowSelectionInterval(...) in you need to select multiple non contiguous rows.
 
Omar Rashwan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the TableModel i mentioned because I saw that you are retrieving data from a mysql database
and i know that you may suffer for that at the beginning, but the TableModel will save your time for retrieving and presenting Data...

but exactly the setSelectionInterval(0,1) as Rob mentoined its a JTable method not TableModel method...
and it selects for the first row till the second row in JTable the second index is ***inclusive.

and for better understanding of JTable you have to look at these good things
The JTable CellRenderer ,
The JTable TableModel ,
The JTable ColumnModel, The TableRowSorter

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