Two JTable questions

Discussion in 'Java' started by jb, Jun 5, 2006.

  1. jb

    jb Guest

    Well I'm writing a database program that is supposed to store contents
    of a warehouse (well small warehouse, really small warehouse). And to
    have a user-friendly GUI.
    And I thought that displaying entire contents of database (backed by a
    filtering mechanism) is a good idea. I did implement my own TableModel
    - I needed it to respond to changes made in the database, to add
    editing capabilities etc.
    getValue looks like that:
    All columns except one uses default renderer and stores values
    converted to strings.
    The odd-one column returns a class named ExpenditureDsplayPanelv2 that
    is extending JPanel that consists of combo box, and a button. It also
    uses custom home-brewed renderer that just returns the value stored in
    this cell.
    There is the extract of the getValueAt method
    switch(column){
    case NAMECOLUMNNUMBER: // its static final int
    try{
    return productVect.get(row).getName();
    }
    catch(ZZIllegalEx e){
    return notSetMessage; //A string too.
    }

    //Other columns had been cut.

    case EXPENDITURESCOLUMNNUMBER:
    return new ExpenditureDsplayPanelv2 ( // <- Here (extends
    JPanel)
    productVect.get(row),
    getOwner()
    );
    }

    Renderer looks like that:
    public Component getTableCellRendererComponent(JTable arg0, Object
    arg1,
    boolean arg2, boolean arg3, int arg4, int arg5) {
    return (Component) arg1; //Works since arg1 is a JPanel thus
    Component
    }

    First problem is that the whole table works slooow (the Table has
    approx. 100 rows, and 11 columns).
    So is the slowness a fault of my clumsy programming (well I admit it is
    my first contact with JTables), and if so how could I make it faster.
    Just give me some hints - i'll work out the rest myself ;-).
    The second is that ExpenditureDsplayPanelv2 (as I have said it extends
    JPanel) though displaying properly, doesn't react on clicking on it
    (while when not in JTable it works ). Once again is it fault of my
    clumsiness, or I just over-estimated power of JTable. And if having
    user responding button as a part of JTable is impossible please suggest
    me how to go round it. And setting this collumn as editable won't work.

    Thanks in advance :)
    -jb
     
    jb, Jun 5, 2006
    #1
    1. Advertising

  2. jb

    John Guest

    jb wrote:
    > Well I'm writing a database program that is supposed to store contents
    > of a warehouse (well small warehouse, really small warehouse). And to
    > have a user-friendly GUI.
    > And I thought that displaying entire contents of database (backed by a
    > filtering mechanism) is a good idea. I did implement my own TableModel
    > - I needed it to respond to changes made in the database, to add
    > editing capabilities etc.
    > getValue looks like that:
    > All columns except one uses default renderer and stores values
    > converted to strings.
    > The odd-one column returns a class named ExpenditureDsplayPanelv2 that
    > is extending JPanel that consists of combo box, and a button. It also
    > uses custom home-brewed renderer that just returns the value stored in
    > this cell.
    > There is the extract of the getValueAt method
    > switch(column){
    > case NAMECOLUMNNUMBER: // its static final int
    > try{
    > return productVect.get(row).getName();
    > }
    > catch(ZZIllegalEx e){
    > return notSetMessage; //A string too.
    > }
    >
    > //Other columns had been cut.
    >
    > case EXPENDITURESCOLUMNNUMBER:
    > return new ExpenditureDsplayPanelv2 ( // <- Here (extends
    > JPanel)
    > productVect.get(row),
    > getOwner()
    > );
    > }
    >
    > Renderer looks like that:
    > public Component getTableCellRendererComponent(JTable arg0, Object
    > arg1,
    > boolean arg2, boolean arg3, int arg4, int arg5) {
    > return (Component) arg1; //Works since arg1 is a JPanel thus
    > Component
    > }
    >
    > First problem is that the whole table works slooow (the Table has
    > approx. 100 rows, and 11 columns).
    > So is the slowness a fault of my clumsy programming (well I admit it is
    > my first contact with JTables), and if so how could I make it faster.
    > Just give me some hints - i'll work out the rest myself ;-).
    > The second is that ExpenditureDsplayPanelv2 (as I have said it extends
    > JPanel) though displaying properly, doesn't react on clicking on it
    > (while when not in JTable it works ). Once again is it fault of my
    > clumsiness, or I just over-estimated power of JTable. And if having
    > user responding button as a part of JTable is impossible please suggest
    > me how to go round it. And setting this collumn as editable won't work.
    >
    > Thanks in advance :)
    > -jb


    Perhaps the problem can be put down to the JDBC implementation? Some
    database may implement scrollable cursors in slow way perhaps? Have
    you tried reading the results of the entire query into an array or
    something? that might speed it up. Other than that I would run it
    through a profiler.
     
    John, Jun 8, 2006
    #2
    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. Tivo Escobar
    Replies:
    1
    Views:
    7,363
    manusa
    Apr 12, 2007
  2. GenxLogic
    Replies:
    3
    Views:
    1,296
    andrewmcdonagh
    Dec 6, 2006
  3. RC
    Replies:
    0
    Views:
    340
  4. Tintin92
    Replies:
    1
    Views:
    1,729
    Andrew Thompson
    Feb 14, 2007
  5. Haircuts Are Important
    Replies:
    3
    Views:
    340
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page