enum question from newbie

Discussion in 'Java' started by Rusty Wright, Jan 4, 2005.

  1. Rusty Wright

    Rusty Wright Guest

    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?
    Rusty Wright, Jan 4, 2005
    #1
    1. Advertising

  2. 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.
    Andrew McDonagh, Jan 4, 2005
    #2
    1. Advertising

  3. Rusty Wright

    Rusty Wright Guest

    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 <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.
    Rusty Wright, Jan 4, 2005
    #3
  4. Rusty Wright

    Rusty Wright Guest

    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 <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.
    Rusty Wright, Jan 4, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    525
  2. Eric Sosman
    Replies:
    3
    Views:
    771
    Mayeul
    Feb 26, 2010
  3. Wojtek
    Replies:
    1
    Views:
    486
  4. Lew
    Replies:
    0
    Views:
    527
  5. Roedy Green
    Replies:
    0
    Views:
    720
    Roedy Green
    Feb 27, 2010
Loading...

Share This Page