• 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

Issue with click event on a custom JToggleButton in a JTable

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

This is basically a repost of my question since i have not been able to find a solution so far http://stackoverflow.com/questions/9588384/placing-jtogglebutton-with-jpanel-within-into-a-jtable-cell

The issue is, that i have a custom button in a table and the click event gets triggered only on the second click in the table cell. If i remove the panel within the custom button it works as intended (i need this panel though). I tried using JLayeredPane instead but faced the same issue that only on second click does the button get clicked. Any suggestions how to have the click event propagated immediately to the button?


Below is a sample code.

Many thanks.
 
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem is the table takes the first click, for the cell selection.

in the absence of a simple/sensible answer, here's your dose of brittle code for the week (maybe year)


you'll need to make 'table' final, and if you don't like doClick(), you can change it to ...setSelected(!...isSelected()).

did I mention the code is extremely brittle?

[edit]
a little less brittle, but only just (gets rid of the getParent()'s)
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wasn't there a method which accepted an int which indicated when the "editing" should start? Default was 2 clicks. Or am I thinking of something else?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there's DefaultCellEditor's setClickCountToStart(..)
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah yes. Thats the one I was thinking of.
Thanks Michael!
 
Denis Wen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OMG, thanks so much. It works, you saved my day (and career, LOL:)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic