need JTable help

F

Fred

Got a problem where I'm looking at a JTable while data is being added to the
bottom. Everytime data is added, I lose my selected row. Is there some way
to prevent the addition of rows to cause my currently selected row to be
unselected?
Thanks, -Fred
 
E

Elie De Brauwer

Got a problem where I'm looking at a JTable while data is being added to the
bottom. Everytime data is added, I lose my selected row. Is there some way
to prevent the addition of rows to cause my currently selected row to be
unselected?
Thanks, -Fred


Why not simply store the selected row before you add data to the model and
reselect it afterwards ?

hth

--
Elie De Brauwer
http://www.de-brauwer.be

No animals were hurt and no microsoft products were used during the
creation of this e-mail
 
K

Kleopatra

Fred said:
Got a problem where I'm looking at a JTable while data is being added to the
bottom. Everytime data is added, I lose my selected row. Is there some way
to prevent the addition of rows to cause my currently selected row to be
unselected?

Sounds like your model fires an incorrect event - selection is cleared
after dataChanged and structureChanged. So make sure the model fires
rowsInserted.

Greetings
Jeanette

PS: comp.lang.java.gui is the group focused on these kinds of issues -
you may consider to post ui-related questions there in future.
 
K

Kleopatra

Elie said:
Why not simply store the selected row before you add data to the model and
reselect it afterwards ?

Why not simply refrain from answering if you only have a vary vague idea
(and untested, I bet) about both problem and solution?

Jeanette
 
D

David Segall

Kleopatra said:
Why not simply refrain from answering if you only have a vary vague idea
(and untested, I bet)
about both problem and solution?
I'm sure you tested this proposed solution before you criticized the
post. Why not just tell us what is wrong with it?
 
K

Kleopatra

David said:
I'm sure you tested this proposed solution before you criticized the
post. Why not just tell us what is wrong with it?

Why not open a door by cracking it with an axe and repair it after you
entered/left?

At times I'm sick and tired of wild and random guesses about
"solutions". They are white noise. That's detrimental to the group's
usefulness because it binds time and effort:

a) of the OP by making her/him explore blind alleys
b) all readers of the group - it's just another post to at least scim
over
c) future readers of the archive which may be pointed into a fruitless
round of a)

Jeanette
 
F

Fred

Actually, that is what I'm doing. But data is pumping into the table faster
than java can redraw it. I added code to call JTable.setSelectedRowInterval
( savedRow, savedRow); but all I get is a flickering blue highlighted line.
The selected row appears to be deselected far more than selected, so this
isn't good enough. I really want to lock the user's selection to a certain
row until the user purposely chooses another row.

I was hoping someone knew a JTable secret which would help me out here.

-Fred
 
F

Fred

Wow, that just might be my problem. I think I might be firing dataChanged.
Wish I could check this sooner, but I have wait until I get back into the
office. Thanks for your help.

-Fred
 
D

David Segall

Kleopatra said:
Why not open a door by cracking it with an axe and repair it after you
entered/left?
Thank you Jeanette. All you needed to do was to include that in your
original post, preferably in more technical, if less colourful,
language. You would have saved the world from a) and c) below. As it
was you just contributed to b). You are entitled to vent and it makes
Usenet a more entertaining resource but please include the basic
information in the post. Many of your readers, including me, do not
have the experience to choose between alternative solutions without
some guidance.
 
A

Andrew Thompson

Thank you Jeanette. All you needed to do was to include that in your
original post, preferably in more technical, if less colourful,
language. You would have saved the world from a) and c) below.

I think you will find that Jeanette's first post at 7:19
<http://google.com/groups?th=d5740e2a58dc92cb#link7>

...seemed to be the answer to a) and c), as indicated by the OP..
<http://google.com/groups?th=d5740e2a58dc92cb#link8>

Whereas the post to which you are referring
was made at 3 mins later at 7:22,
<http://google.com/groups?th=d5740e2a58dc92cb#link3>
(presumably to ensure that the less
effective/ineffective method was not
left 'open' as the best way
to approach the problem.)

[ Dammit - just realised this post will change
those anchor numbers.. look closely at the
thread itself.. ]
 
F

Fred

In any case, Jeanette was correct. I was firing the wrong event. I switched
from fireTableChanged to fireTableRowsInserted and it worked. I certainly
do appreciate it.

-Fred

Andrew Thompson said:
Thank you Jeanette. All you needed to do was to include that in your
original post, preferably in more technical, if less colourful,
language. You would have saved the world from a) and c) below.

I think you will find that Jeanette's first post at 7:19
<http://google.com/groups?th=d5740e2a58dc92cb#link7>

..seemed to be the answer to a) and c), as indicated by the OP..
<http://google.com/groups?th=d5740e2a58dc92cb#link8>

Whereas the post to which you are referring
was made at 3 mins later at 7:22,
<http://google.com/groups?th=d5740e2a58dc92cb#link3>
(presumably to ensure that the less
effective/ineffective method was not
left 'open' as the best way
to approach the problem.)

[ Dammit - just realised this post will change
those anchor numbers.. look closely at the
thread itself.. ]

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
A

Andrew Thompson

...
Why not ... ?

Hi Elie..

My comments later in this thread might
give the wrong impression.

I think you were *right* to post an idea.

This is a discussion forum, though
primarily geared to Q&A.

There are occasions when I myself post
information that I am unsure of.
Two ways to lessen the possible
repercussions are to..

a) Make *very* clear it is an 'off-the-cuff',
untested solution..

b) Draft a response but 'save' it in your
newsreader, if the respondent does not have
any answers by the next day ..post it.

[ I have drafted hundreds, ..and hundreds of
posts that I deleted the next day when it
became obvious the correct answer (often a
'different' answer to my own) was posted. ;-) ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top