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

ListSelectionListener() on JComboBox in JTable

88 views
Skip to first unread message

RVince

unread,
Jan 25, 2010, 7:31:28 AM1/25/10
to
I have a ListSelectionListener to my JTable to pick up when given
cell with a JComboBox has changed.(in Col 0) When that occurs, the
rest of the data for that row needs to change to reflect the new
chosen value in the JComboBox, and the table redisplayed. I am trying
to use model..fireTableDataChanged() at the end to accomplish this,
without success.

Can anyone show me what I have misunderstood here about how to do
this? Clearly the task I am describing is nothing novel, and must have
been done a million times before, but for some reason I cannot find a
sample of how to accomplish it, and I'm not even sure I am on the
right path at all here. Thanks, RVince

table.getSelectionModel().addListSelectionListener(
new ListSelectionListener() {

@Override
public void valueChanged(ListSelectionEvent arg0) {
if(table.getSelectedColumn
()==0{
//do something that
changes the model's
// data vector based
on the value in the chosen
//cell's JComboBox
((DefaultTableModel)
table.getModel()).fireTableDataChanged();
}
}
}
};

John B. Matthews

unread,
Jan 25, 2010, 9:52:25 AM1/25/10
to
In article
<64a5a91b-b495-4e7d...@q4g2000yqm.googlegroups.com>,
RVince <rvin...@hotmail.com> wrote:

> Can anyone show me what I have misunderstood here about how to do
> this?

Not without an <http://sscce.org/>, such as may be found here:

<http://java.sun.com/docs/books/tutorial/uiswing/examples/components/
TableRenderDemoProject/src/components/TableRenderDemo.java>

<http://groups.google.com/group/comp.lang.java.gui/msg/79840a35efd248c1>

See also:

<http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Lew

unread,
Jan 25, 2010, 9:57:41 AM1/25/10
to
RVince wrote:
> table.getSelectionModel().addListSelectionListener(
> new ListSelectionListener() {
>
> @Override
> public void valueChanged(ListSelectionEvent arg0) {
> if(table.getSelectedColumn
> ()==0{
> //do something that
> changes the model's
> // data vector based
> on the value in the chosen
> //cell's JComboBox
> ((DefaultTableModel)
> table.getModel()).fireTableDataChanged();
> }
> }
> }
> };

John B. Matthews already pointed out the need for an SSCCE and gave you some
examples to follow. Also, drop the use of unreadable indentation for Usenet
posts. Your indentation was insane. Use a maximum of four spaces (for Pete's
sake, not TABs!) per indent level.

People are far less willing to help when you make it difficult for them.

--
Lew

ninjapiza

unread,
Dec 17, 2010, 10:33:42 AM12/17/10
to
I think that the question is rather how to update combobox selection...


0 new messages