Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JTable's JButton events

10 views
Skip to first unread message

ba...@hbs.edu

unread,
Feb 4, 1999, 3:00:00 AM2/4/99
to
I have some JButtons in my JTable, and a renderer to
show them. However, events are not propagated to the
JButtons' ActionListeners. How is this supposed to
work - if a JButton belongs to a JTable, is it the
JTable who must handle the events and pass them on to
the right JButton? I hope not...

Nor can I see anything obvious like "TableCellEvent".

So, how do you register those JButtons?

Thanks!
David Barts

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Mr. Tines

unread,
Feb 5, 1999, 3:00:00 AM2/5/99
to
###

On Thu, 04 Feb 1999 23:46:39 GMT, in <79dbgs$gq3$1...@nnrp1.dejanews.com>
ba...@hbs.edu wrote.....

> I have some JButtons in my JTable, and a renderer to
> show them. However, events are not propagated to the

You do not have *any* JButtons in your JTable. You have
a lot of pictures of JButtons, which is a rather different
thing. All a renderer does is, when the table says
"Here's all i know about a cell", to reply "And here's
how to draw it".

> JButtons' ActionListeners. How is this supposed to
> work - if a JButton belongs to a JTable, is it the
> JTable who must handle the events and pass them on to
> the right JButton? I hope not...
>
> Nor can I see anything obvious like "TableCellEvent".
>
> So, how do you register those JButtons?

You can simulate this by putting a mouse listener on the
JTable, and using the get cell from position method of
the table to figure out which cell, then tweaking the
appearance of the cell to reflect mouse down, and firing
an action if the depressed button picture also gets a
mouse up.

-- PGPfingerprint: BC01 5527 B493 7C9B 3C54 D1B7 248C 08BC --
_______ {pegwit v8 public key =581cbf05be9899262ab4bb6a08470}
/_ __(_)__ ___ ___ {69c10bcfbca894a5bf8d208d001b829d4d0}
/ / / / _ \/ -_|_-< www.geocities.com/SiliconValley/1394
/_/ /_/_//_/\__/___/@windsong.demon.co.uk PGP key on page

### end pegwit v8 signed text
3cf9a350ac78986991d65b971f08f3335d16e03753ec605a9d1970c56aa5
91b4836c8a0e098a9e0ae31324f7033ac8609f066d8dae4334448342380b


ba...@hbs.edu

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
Mr. Tines wrote:

> > JButtons' ActionListeners. How is this supposed to
> > work - if a JButton belongs to a JTable, is it the
> > JTable who must handle the events and pass them on to
> > the right JButton? I hope not...
> >
> > Nor can I see anything obvious like "TableCellEvent".
> >
> > So, how do you register those JButtons?
>
> You can simulate this by putting a mouse listener on the
> JTable, and using the get cell from position method of
> the table to figure out which cell, then tweaking the
> appearance of the cell to reflect mouse down, and firing
> an action if the depressed button picture also gets a
> mouse up.

I've had some progress with hacks like this:

public Component
getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column ) {
if ( isSelected && hasFocus ) {
// execute button's callback code ...
table.clearSelection();
}
...
}

Perhaps something could also be done via TableCellEditor (also hack-like).

However, this clearly goes against all the talk of "code reuse" --
I can't reuse a JButton within my GUI!

There either has to be a better way or it's one down for JavaSoft.

Dave Postill

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
[This followup was posted to comp.lang.java.programmer and a courtesy copy was sent to the cited
author, ba...@hbs.edu]

In article <79dbgs$gq3$1...@nnrp1.dejanews.com>, on Thu, 04 Feb 1999 23:46:39 GMT, ba...@hbs.edu wrote:

| I have some JButtons in my JTable, and a renderer to
| show them. However, events are not propagated to the

| JButtons' ActionListeners. How is this supposed to
| work - if a JButton belongs to a JTable, is it the
| JTable who must handle the events and pass them on to
| the right JButton? I hope not...
|
| Nor can I see anything obvious like "TableCellEvent".
|
| So, how do you register those JButtons?

See "Display any JComponent in a cell".

Extract:

"the TableUI class passes on the event that initiated the
edit ( the mouse_pressed event ) to the editor component.
Since many components expect mouse_released and mouse_clicked
to follow, we oblige these components."

<http://www.codeguru.com/java/articles/162.shtml>
davep
--
Dave Postill Investment Intelligence Systems Corp
Galaxy Support Leader +44 (0)171 628 6960 [voice]
<mailto:da...@iisc.co.uk> +44 (0)171 638 7528 [fax]
<mailto:dave.p...@pobox.com> <http://www.iisc.co.uk>

ba...@hbs.edu

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
In article <36cc52cd...@news.demon.co.uk>,

da...@iisc.co.uk wrote:
> Extract:
>
> "the TableUI class passes on the event that initiated the
> edit ( the mouse_pressed event ) to the editor component.
> Since many components expect mouse_released and mouse_clicked
> to follow, we oblige these components."
>
> <http://www.codeguru.com/java/articles/162.shtml>
> davep

That's great, thanks!

0 new messages