0

I am new to swings,my requirement are 1. I need to create a rowheader for the jtable. 2. Add up and down buttons (listeners for moving/changing the row position). 3. when I change the row position I should not change the rowheader number. 4. Need to retrieve the row data based on the rowheader index . 5. Already one userdefined class extend jtable and model is there with data.I need to add the above 4 points requirements to this table.I need to use Jlist or again jtable for adding rowheader(if again jtable then basic jtable with data is not working properly.) I tried with many google references,but the problem is I could not integrate all the functionalites at same time and even I could not find the solution for points 3 and 4.Please do consider the requirement.Sorry for typo mistakes. Thank in advance.

1 Answers1

0

I need to create a rowheader for the jtable.

Check out the Fixed Column Table.

You create a normal TableModel. Then you can specify the first row of the model to be used as the row header. The code will then create two table that share the same TableModel. One table will be used as the row header, the other will be displayed in the viewport of the scroll pane.

If you want to sort the tables you will then also need to share the RowSorter with code something like:

table.setAutoCreateRowSorter(true);
fct.setRowSorter(table.getRowSorter());
table.setUpdateSelectionOnSort(true);
fct.setUpdateSelectionOnSort(false);
camickr
  • 321,443
  • 19
  • 166
  • 288
  • Hi,Thanks for the reply,I have added the rowheader with help of jlist.I am not sorting any of the data ,just moving the row up and down.Sorry forgot to give the example I did. – user5466642 Oct 05 '17 at 06:27
  • @user5466642, `,I have added the rowheader with help of jlist` - well, I just gave you a solution that uses 2 JTables that share the same model. The point being that if you move the row up/down in the model, then both JTables will repaint themselves since they share the same model. – camickr Oct 05 '17 at 14:06
  • Hi,Thank you for the answer,as could you please help out with sample code or references(I am trying this long time followed many references of rowheader of jtable.,but all tries went to vain.).As I tried the same model but could not select the complete row only few columns in the row are selected.I have taken the reference you gave like fixed column table when I added 0 th column is added to the fixed table and not getting deleted from main table . – user5466642 Oct 09 '17 at 05:26
  • @user5466642, I did give you sample code and references. If you need more help post a proper [mcve] that demonstrates what problem you are having using the code provided. – camickr Oct 09 '17 at 14:21
  • Hi ,thank you ,it is my code bugs which are dependent on other.Now I am able to get that. – user5466642 Feb 11 '18 at 09:01