enum question from newbie

R

Rusty Wright

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?
 
A

Andrew McDonagh

Rusty said:
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.
 
R

Rusty Wright

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 said:
Rusty said:
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.
 
R

Rusty Wright

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 said:
Rusty said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top