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 / August 2007

Tip: Looking for answers? Try searching our database.

where to set JTable's column identifier

Thread view: 
Ray Ma - 27 Aug 2007 20:38 GMT
Hi, All,

I've searched through the forum but no closely relevant topics that
seems close to my question.

I tried to set an identifier for each column of my JTable, using the
tableModel method setColumnIdentifiers():
e.g. in my tableModel I use:

String [] COLUMN_NAMES = {"column1","column2","column3"};
this.setColumnIdentifiers(COLUMN_NAMES);

then in my JTable,
I try to remove a column by calling:
this.removeColumn(this.getColumn(COLUMN_NAMES[0]);

The compiler always report error:
java.lang.IllegalArgumentException: Identifier not found

which means it can't recoginze the column identifier:  COLUMN_NAMES[0]

I can use:
TableColumnModel tcm = this.getTableColumnModel();
tcm.removeColumn(tcm.getColumn(0));

But I want to use myTable.removeColumn() directly, instead of using
the tableColumnModel.removeColum(i);

How should I do?

Thanks.
Roedy Green - 28 Aug 2007 06:09 GMT
>which means it can't recoginze the column identifier:  COLUMN_NAMES[0]

If you are impatient, and just want to get your code to work without
figuring out why your existing code is failing,  keep track of your
columns by number.  Then you can use TableModel.getColumn(i );

There may be some distiction between column headers and ids that is
tripping you up.  I suggest dumping out ids and headers frequently.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Ray Ma - 28 Aug 2007 16:09 GMT
> There may be some distiction between column headers and ids that is
> tripping you up.  I suggest dumping out ids and headers frequently.
> --
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

On Aug 27, 10:09 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:

> There may be some distiction between column headers and ids that is
> tripping you up.  I suggest dumping out ids and headers frequently.

Thanks Roedy. Your suggestion helps me to debug. Actually the problem
cause is not
the incorrect column id. It's because I try to access a column by its
ID in my code
after the column has been "hidden"(removed from the column model)

The following code lines have the same output in MyJTable class:

       System.out.println("in TableColumn column 0 ID: "+
getColumn("column_0").getIdentifier());
       System.out.println("in TableModel  column 0 ID = "+
getModel().getColumnID(0));
       System.out.println("in TableModel  column 0 Name = "+
getModel().getColumnName(0));
       System.out.println("in TableColumnModel column 0 ID = "+
getColumnModel().getColumn(0).getIdentifier());

output: "column_0"


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.