• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maintaining Column order in JTable

 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just spent an hour or so reading through the relevant docs and searching a little but could only find one way to implement this, maybe you guys have some input regarding this.
Re-ordering columns is a nice feature, and I wont disable it, but beyond that users dont expect to have to re-order the columns everytime they search, and I can seem to find a way to get the current order before re-populating the JTable and then re-setting the order to what was previously configured.
So far I could only come up with the following
implement TableColumnModelListener, specifically columnMoved(TableColumnModelEvent e) , then use the TableColumnModelEvent to get the fromIndex and toIndex, maintain the order in some or other collection, and then use the JTable's method moveColumn(int column, int targetColumn) to re-position the columns after searching.
Is this the only way?
maybe I'm just lazy but I'm disappointed not to have found something along the lines of getColumnModel().getColumnOrder()
I must be lazy because that sounds more ridiculous the more I think about it, anyhat, any input will be appreciated.
just found a second possibility, just before searching I could iterate through the columns and use JTable's getColumnName(int column) to save the current order, and move the columns after searching.
If these are the only 2 ways which is better in your opinion?
else any suggestions are welcome
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FWIW the second suggested solution is really simple, took 5 minutes to implement it cleanly, 2 very simple methods, one to get the order and one to re-order, thats it, now could I be penalised for implementing something thats already available?
If it is I've completely missed it
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate to bump a dead thread but I'd like some feedback from at least one person who has passed with a good score already.
Did you implement column order maintenance?
why I ask is because this issue got me thinking that perhaps the problem is not with my GUI/JTable, but rather with my server.
I say this because I feel maybe its the servers responsibility to provide the columns in the order the user requested, and maybe I should be overloading the read method to read (int recNo, int[] columns) , I will continue to provide all the columns as I'm doing now, effectively a "select * from room", and what can be seen as WHERE clauses as well, ie "where date >= today" , but beyond that this will allow the user to shift columns about, and when searching the controller will send the current column order and expect the results to be in that order as well.
thats how queries work generally anyway, but is this expected in this system or am I getting cold feet about submitting this system and just trying to find fault where there isn't , considering the scope of this application
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi TQ
I did not implement column order maintenance. It was on my list of things to fix, but I had a self imposed deadline, and decided not to bother.
I didn't loose any points for the GUI (old assignment).
Regards, Andrew
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Monkhouse:
Hi TQ
I did not implement column order maintenance. It was on my list of things to fix, but I had a self imposed deadline, and decided not to bother.
I didn't loose any points for the GUI (old assignment).
Regards, Andrew

Hi Andrew, from what you just said, and your score, I wont include it either, absolutely nothing to gain.
It was just one of those last minute test user responses I thought I'd better include.
Thanks yet again
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi TQ
From your comment earlier, I thought you had implemented saving the order, and then restoring it when you got the data back from the server.
This seems to me to be a nice user friendly feature, so I would leave it in.
Regards, Andrew
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Monkhouse:
Hi TQ
From your comment earlier, I thought you had implemented saving the order, and then restoring it when you got the data back from the server.
This seems to me to be a nice user friendly feature, so I would leave it in.
Regards, Andrew


Hi Andrew, I did implement it, and thought it was quite simple and clean, until I thoroughly tested it, moveColumn obviously bumps the target column out as well, so I ended up with a loop that shifted the columns to the previous state, and then a loop that checked again and possibly shifted it again, then changed that to save where moveColumn bumped the target column to, and then it got annoying because it really is time to submit now, I cant keep fixing things, especially not things that dont really have to be in, this week I go through final user acceptance, and then its time to be brave and submit what I have, and by simply removing that entirely I'm left with zero bugs, and nothing on my todo list except to update screenshots for help docs, and maintaining the column order raised another issue that would have to be addressed as well, although sort of 2 birds with one stone type problem, thats the size of the columns, I display the columns in a size suitable for the relevant data, but if the user re-sizes the columns his previous settings are lost as well.
Regards, TQ
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi TQ
and then it got annoying because it really is time to submit now

Ahh, the "I am sick of this thing, so it is time to submit" situation.
I remember that feeling too well.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic