Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > enum question from newbie

Reply
Thread Tools

enum question from newbie

 
 
Rusty Wright
Guest
Posts: n/a
 
      01-04-2005
It seems to me that enums are what I should use for the indices of an
array where the array indices correspond to the columns in a JTable.
My JTable implements a simple sign-in wait list and has 3 columns,
Name, Sign-In Time, and Delete. (In the JTable Delete is a check box
for deleting someone from the wait list.)

My enum is as follows:

public enum Cols {
NAME, TIME, DELETE
}

If I have a row from the table, which is an array of 3 objects, and I
want to check to see if that row is to be deleted, the code for
getting the row looks something like this:

Object[] row;

row = get_Row();

The code to check to see if it's to be deleted is

if (row[Cols.DELETE.ordinal()].toString().equals("true"))

Nevermind all the baloney with toString() and equals(); what bothers
me is that I have to use ordinal(). That just seems so klunky.

Am I going about this the wrong way?
 
Reply With Quote
 
 
 
 
Andrew McDonagh
Guest
Posts: n/a
 
      01-04-2005
Rusty Wright wrote:
> It seems to me that enums are what I should use for the indices of an
> array where the array indices correspond to the columns in a JTable.
> My JTable implements a simple sign-in wait list and has 3 columns,
> Name, Sign-In Time, and Delete. (In the JTable Delete is a check box
> for deleting someone from the wait list.)
>
> My enum is as follows:
>
> public enum Cols {
> NAME, TIME, DELETE
> }
>
> If I have a row from the table, which is an array of 3 objects, and I
> want to check to see if that row is to be deleted, the code for
> getting the row looks something like this:
>
> Object[] row;
>
> row = get_Row();
>
> The code to check to see if it's to be deleted is
>
> if (row[Cols.DELETE.ordinal()].toString().equals("true"))
>
> Nevermind all the baloney with toString() and equals(); what bothers
> me is that I have to use ordinal(). That just seems so klunky.
>
> Am I going about this the wrong way?


Yep, You should add a tableCellEditor to the Delete column which will be
called when the user clicks the checkbox. The celleditor will be given
the row & column co-ords. Therefore it can easily remove the correct row
from the TableModel. Not an enum insight.
 
Reply With Quote
 
 
 
 
Rusty Wright
Guest
Posts: n/a
 
      01-04-2005
Ok, thanks. That's good to know. I'll have a look at
tableCellEditor. That may clear up other areas where I'm using an
enum as an array index for the table columns.

But I still am curious about using enums as array indices. Is that
just outmoded thinking on my part with my wanting to use them that
way?

Andrew McDonagh <(E-Mail Removed)2s.com> writes:

> Rusty Wright wrote:
> > It seems to me that enums are what I should use for the indices of an
> > array where the array indices correspond to the columns in a JTable.
> > My JTable implements a simple sign-in wait list and has 3 columns,
> > Name, Sign-In Time, and Delete. (In the JTable Delete is a check box
> > for deleting someone from the wait list.)
> >
> > My enum is as follows:
> >
> > public enum Cols {
> > NAME, TIME, DELETE
> > }
> >
> > If I have a row from the table, which is an array of 3 objects, and I
> > want to check to see if that row is to be deleted, the code for
> > getting the row looks something like this:
> >
> > Object[] row;
> >
> > row = get_Row();
> >
> > The code to check to see if it's to be deleted is
> >
> > if (row[Cols.DELETE.ordinal()].toString().equals("true"))
> >
> > Nevermind all the baloney with toString() and equals(); what bothers
> > me is that I have to use ordinal(). That just seems so klunky.
> >
> > Am I going about this the wrong way?

>
> Yep, You should add a tableCellEditor to the Delete column which will be
> called when the user clicks the checkbox. The celleditor will be given
> the row & column co-ords. Therefore it can easily remove the correct row
> from the TableModel. Not an enum insight.

 
Reply With Quote
 
Rusty Wright
Guest
Posts: n/a
 
      01-04-2005
I'm still not convinced that a tableCellEditor solves all of my
problems.

I simplified my example; there's also a TOP column, which is a check
box, which when selected moves the entry to the top of the list. The
list is sorted by the TIME column so the Top function just fiddles the
checked row's time to be less than the top row's and re-sorts the
list. In this situation I'm working with both the TOP and TIME
columns, as well as another row.

Andrew McDonagh <(E-Mail Removed)2s.com> writes:

> Rusty Wright wrote:
> > It seems to me that enums are what I should use for the indices of an
> > array where the array indices correspond to the columns in a JTable.
> > My JTable implements a simple sign-in wait list and has 3 columns,
> > Name, Sign-In Time, and Delete. (In the JTable Delete is a check box
> > for deleting someone from the wait list.)
> >
> > My enum is as follows:
> >
> > public enum Cols {
> > NAME, TIME, DELETE
> > }
> >
> > If I have a row from the table, which is an array of 3 objects, and I
> > want to check to see if that row is to be deleted, the code for
> > getting the row looks something like this:
> >
> > Object[] row;
> >
> > row = get_Row();
> >
> > The code to check to see if it's to be deleted is
> >
> > if (row[Cols.DELETE.ordinal()].toString().equals("true"))
> >
> > Nevermind all the baloney with toString() and equals(); what bothers
> > me is that I have to use ordinal(). That just seems so klunky.
> >
> > Am I going about this the wrong way?

>
> Yep, You should add a tableCellEditor to the Delete column which will be
> called when the user clicks the checkbox. The celleditor will be given
> the row & column co-ords. Therefore it can easily remove the correct row
> from the TableModel. Not an enum insight.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: an enum question - how to convert enum type to a string? Roedy Green Java 0 02-27-2010 04:52 AM
Re: an enum question - how to convert enum type to a string? Wojtek Java 1 02-27-2010 03:44 AM
Re: an enum question - how to convert enum type to a string? Lew Java 0 02-27-2010 03:40 AM
Re: an enum question - how to convert enum type to a string? Eric Sosman Java 3 02-26-2010 03:36 PM
enum within an enum - Java 6 06-13-2005 12:51 AM



Advertisments