Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with click event on a custom JToggleButton in a JTable  RSS feed

 
Denis Wen
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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)
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
there's DefaultCellEditor's setClickCountToStart(..)
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
OMG, thanks so much. It works, you saved my day (and career, LOL:)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!