Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2005

Tip: Looking for answers? Try searching our database.

moving  (JTable) columns

Thread view: 
:-o - 26 Nov 2005 18:46 GMT
Thanks,

I'm using a JTable (with headers) and I press a button and the cells are filled
with data from a source I specify.

I'd like the operator to be able to move the columns while data is being filled,
but problems occur as the data
is sent to the column where the data was (prior to a move).

So if I have 2 columns with the 1st column header lastname and the 2nd column
being a boolean checkbox with header brown eyes (true or false), when I switch
the 2 columns, column 2 cell data SHOULD be lastname and column one SHOULD be
checkbox (true or false), but its just the opposite (prior to column movement).

Any ideas?
Roedy Green - 27 Nov 2005 01:02 GMT
>I'm using a JTable (with headers) and I press a button and the cells are filled
>with data from a source I specify.

When you use the column reorder, your datamodel should be unaffected.
By any chance, are you pouring data into different slots on column
reorder?

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

:-o - 27 Nov 2005 12:46 GMT
>>I'm using a JTable (with headers) and I press a button and the cells are
>>filled
[quoted text clipped - 3 lines]
> By any chance, are you pouring data into different slots on column
> reorder?

I think I know whats happening.  I have a constants file with final public
static definitions and within this
file, I have an final public static array which controls the columns that the
s/w is locked into, which I'll need to redesign.

final public static String[] columns {"SSN", "LastName", "FirstName", etc......}

such that when I do a findColumn (after column movement), this is where it
hiccups.

Thanks.

> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 27 Nov 2005 17:43 GMT
>I think I know whats happening.  I have a constants file with final public
>static definitions and within this
[quoted text clipped - 5 lines]
>such that when I do a findColumn (after column movement), this is where it
>hiccups.

1. JTable has a get TableColumnModel() method.

2. You can then use getTableColumn( i ) to get the TableColumn object
for the ith column.

3. your TableColumn object has a method getModelIndex() that tells
where the data for that column comes from in the model.

When any column moves, the mapping for step (2) changes, and listeners
can get a columnMoved event.

I don't think you should be doing any findColumn.

For an experment set up a TableColumnModelListener that fires a
fireTableDataChanged.

That is not the proper solution, but if that solution fails, you know
the problem is not in failing to refresh.

Are you caching any of the TableColumns?  you have to refresh that
after a colmunMoved.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

:-o - 30 Nov 2005 01:13 GMT
>>I think I know whats happening.  I have a constants file with final public
>>static definitions and within this
[quoted text clipped - 28 lines]
> Are you caching any of the TableColumns?  you have to refresh that
> after a colmunMoved.

No I'm not.  I'll have to do more research.

> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.
Kari Ikonen - 27 Nov 2005 16:52 GMT
> I'd like the operator to be able to move the columns while data is being
> filled, but problems occur as the data
[quoted text clipped - 5 lines]
> column one SHOULD be checkbox (true or false), but its just the opposite
> (prior to column movement).

I'm pretty sure that you have mixed up view indexes and model indexes.

View index is zero based index, indicating column ordering. So this index is
0..N-1 (where N is number of columns). TableColumnModel of table maintains
this view index array. Whenever columns are reordered view indexes of
columns will change.

Model index is index of column in the table model. This index is just some
integer, so that each column have unique number. I.e. there is nothing
requiring these indexes to be zero based.

Model data must be always accessed using model index, thus view index must
be converted into model index when needed. JTable contains necessary
conversion methods for converting between these two indexes.

Signature

KI -- http://kari.world.dy.fi



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.