Article View: borland.public.jbuilder.java.swing
Article #9350Re: JTable, move selected rows using a mouse
From: David M. Karr
Date: Mon, 17 Apr 2000 00:00
Date: Mon, 17 Apr 2000 00:00
35 lines
2411 bytes
2411 bytes
>>>>> "Werner" == Werner Moschina <wmo@stutensee.net> writes:
Werner> Hi Steve,
>> If you drop a JTable into a JScrollPane so that you can see the column
>> headers, these headers can be dragged around to re-order the colunms by
>> default - no coding required.
Werner> I want to move *selected rows* to reorder a table, not the columns.
Werner> That's the way it should work:
Werner> 1. Select one or more rows (SINGLE_INTERVALL_SELCETION) 2. Click on
Werner> these seleted rows and hold mouse button 3. Reorder the rows on the
Werner> fly depending on mouse movement upwards or downwards
Werner> The first step is easy:
Werner> DefaultListSelectionModel lsm;
Werner> lsm.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
Werner> Step 2 is my problem. As soon as the selected rows are clicked the
Werner> selection is cleared, except for the clicked row. How can I avoid
Werner> this behaviour, which listener must be changed?
Werner> Due to my problems in step 2, I couldn't try step 3 yet.
Frankly, I wouldn't try to implement it this way. This would be "surprising"
behavior from the user's point of view. I've done this with auxiliary buttons
attached to the right side of the table that perform "move up" and "move down"
functions. This doesn't depend on dragging, or unexpected non-changes in
selections. Separating the "move" behavior from the table selection also
allows you to implement moves of more than one selected row, including
discontiguous selections. It would be good to make sure your datamodel class
supports this kind of behavior. A simple way to provide it from the
datamodel's point of view would be to implement a "swap" method, given two row
numbers. You can then implement any row movement in terms of that method.
Technical Details
Message-ID:
<uya6cfuk1.fsf@attws.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38F6E0DB.B6552FDE@stutensee.net> <38FABF39.9BCA4B7B@cwcom.co.uk> <38FAF193.2BFFE952@stutensee.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,f0e52445185f02d8 X-Google-Attributes: gid111d45,public From: david.karr@attws.com (David M. Karr) Subject: Re: JTable, move selected rows using a mouse Date: 2000/04/17 Message-ID: <uya6cfuk1.fsf@attws.com> X-Deja-AN: 612338465 Sender: DKarr@WA02513 References: <38F6E0DB.B6552FDE@stutensee.net> <38FABF39.9BCA4B7B@cwcom.co.uk> <38FAF193.2BFFE952@stutensee.net> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing