• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom Cell renderer... A solution?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
As a newbie here I need to know if I code a custom cell renderer for my table, it would solve my problem.

Here is the situation:

I have a table with 2 columns, 2 combo box cells.
I have defined 2 buttons to add and remove the selected rows.
When selecting a combo box cell, it goes to edit mode and if I delete that row and then selecting another row (cell) I am thrown with this exception:
"Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1"

So I thought that a custom cell renderer would solve the problem.

Any ideas?

Cheers.
 
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Erm hard-to-tell as there's no code but I don't think the problem is in the rendering, especially if you can already see the combo boxes.

My guess is maybe the delete code isn't firing the tableRowsRemoved event but I really don't know until I see some code. Try creating a Short Complete Example (Google it) and it might help work out what's wrong.
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, here is the delete code. It is supposed to remove the row from the model, but it seems it is just removing it from the GUI. An I thinks that's why it is throwing arrayIndexOutof Bounds exception - The array inside the combo box is all messed up. Am I missing something here?
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it seems that the rowsRemoved requires a TableModelEvent event. But I am handling that with a mouse clicked event.

Any ideas?

Cheers.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think some more code should give us the idea.
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, that's the way I have created the combo boxes and set the elements into them:



then comes the add and delete codes - see my previous posts.

Thanks.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using just a single column for a comboBox editor, I can reproduce your problem
only if the last row is selected/deleted, then another selected after deletion.

adding this line seems to fix the problem

myjTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

as an aside, you should be using an actionListener for your button instead of a mouseListener,
it's no big deal, just consistency, but if you prefer mouseListener, note that mouseClicked
is definitely not the right choice, as it doesn't always fire. mousePressed is a far better choice.

to test mouseClicked, click and hold, move the mousePointer just a bit, now release. the event won't fire.
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,

Thanks for the tip. I changed the mouseClicked to mousePressed and added that property to the table with no luck. I then tested that same property for the combo box, and to my wonder it accepted the property but it did not solve the problem.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
about the only thing left is to post a compilable/runnable program,
so we can see exactly what's happening.

just the bare bones, comboBox to include new String[]{"a","b","c"} etc
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if that's what you need here we go
Just ignore the first part, Check the code from line 58
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry; was a duplicated post.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, this is what I suggested you post

> about the only thing left is to post a compilable/runnable program,
> so we can see exactly what's happening.
> just the bare bones,...

here's an interesting exercise for you:

copy the code you posted
now go to another pc, one with a java jdk,
but one that doesn't have netbeans, or have any of the micrm package classes
paste the code into notepad and try to compile via the command line

now you will be seeing what we see i.e. we can do nothing with the code you posted.

if you want a solution, you'll have to post something we can compile and run.
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I see. Here are the bare bones (horns)
The attachment plugin of the forum is a headache. It does not accept zip nor txt nor java extensions. I doubt if it accepts any file at all.


Thanks.
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bump!?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a combination of the follwing 2 changes seems to work OK
1) adding the indicated line


2) changing the mouseListener from pressed to released (for remove)
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I will give it a shot.
 
P Plus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you mate. That did solve the problem.

Thanks again everyone.

Cheers.
P.
 
reply
    Bookmark Topic Watch Topic
  • New Topic