Jim Crowell

Greenhorn
+ Follow
since Mar 27, 2009
See above web site...
Syracuse, NY
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jim Crowell


You should be able to cast the DropLocation object to javax.swing.JTable.DropLocation which has methods to return which column, row etc the user is trying to drop the data into.


Thanks.
I did some analysis of my old method and the 'JTable.DropLocation' implementation
and it looked like either way the correct drop point is there once the mouse button
is released. However, the 'JTable.DropLocation' method seemed to better track the
mouse drag movement.

Below is the revised 'canImport' method with my original method commented out…

I have an additional question if I may.
In my 'getSourceActions' override method I return a "TransferHandler.MOVE" int
iff the Table Model column is > 0 [i.e. == 1 of 2]…

Also my JTable [emissariesTable] setting are as follows:
emissariesTable.setDragEnabled(true);
emissariesTable.setDropMode(DropMode.USE_SELECTION);
emissariesTable.setTransferHandler(new JEmissaryReportTransferHandler());

What i need to accomplish is to have the drag String set to a Null String after the drag String is dropped in the destination column cell…

That is what I thought the DnD MOVE process would do.

To satisfy my requirement, I went and added some code to my TransferHandler.
My JTable is dynamic in that rows are added and removed during run time by my code.
Therefore, the added code was somewhat difficult [for me anyway] and still has a bug to be fixed.

My question is as follows:
Have I overlooked something in my basic DnD JTable settings so that
the MOVE will work as I expected without my "kluge" code?

Here is the JEmissaryReportTransferHandler with the added code to perform the MOVE:

Regards,
Jim...
9 years ago


You need to limit which columns can be dragged from so I think you need to override getSourceActions() to return the type of transfer action available on the currently selected cell of the JTable. The cells which can't be dragged from return NONE.



The above advise was just what I needed.
The following is the code that I am currently using successfully:
I probably did not need the 'instanceof' if but I use that approach a lot...



For dropping the data you need to use the canImport() method to limit where the data can be dropped. The TransferSupport object passed into the method can be used to get the DropLocation object which can then be used to determine where the user is attempting to drop the dragged data.



I played with this but was unable to use it as directed.
I ended up adding some custom code to both the 'canImport' override and the 'createTransferable' override methods to [I think] resolve my controls for the 'drop' capability.

I'm still tweaking and testing but I think I am close to my objective...


BTW I take it you are setting the JTable's drop mode to a suitable value and are enabling dragging on the JTable.



Yes, the following code is used:


Thank you for the help.
Regards,
9 years ago
Tony,

How are you determining which table column you are dropping onto are you using the JTable.DropLocation class?


No I am not using the 'DropLocation' class.
This is the kind of help I needed. I did not know of that class.
I just took a quick look at it and will examine it more after I complete this post.

I need to turn off Column 0, Drag from column 1 only and Drop to column 2 only.
In column 1, ideally, I should turn off some row cells also to avoid end user confusion.

FYI: I am developing on an iMac using OS X 10.6 and I am using Java 1.6.0_37.

The following is my code for the AbstractTableModel and the TransferHandler:


Thanks,
Jim...
9 years ago
I have developed a 3 column JTable with DnD capability. I use a TransferHandler subclass and an AbstractTableModel subclass. It is working fine.

However, I have some addition requirement to control the JTable DnD cells, e.g. no DnD for column 0, drag only from column 1 and drop only to column 2.

I studied the TransferHandler methods and added code to several of my override methods but I have not been successful yet.

I think that these requirement should be somewhat common but I have not been able to find any similar documentation using Google.

As is my experience, I suspect I am overlooking something basic and I am making my requirements implementation more difficult then it really is.

Any suggestion?

Regards,

9 years ago
Mike,

I would gladly spend a day setting up a [quote]structured persistence layer[/quote] if I thought I could do it in a day or two.

I think I understand the JPA concept and would like to apply it but I am afraid that the learning curve is steep for me.

From your reply I assume you are saying that my current approach is workable.
Since I am way behind schedule I believe I should proceed with my present plan and, if the stand alone application is
successful, hire someone to implement JPA in an application revision.

I'll get your book and see if that helps me understand what I would need to do to implement JPA in my application.

Thanks for your inputs,
Jim...
Hi,
I am developing a "Form Centric" stand alone Java application that uses the Derby Database and currently uses Java version 5.
Initially, I ignored persistence and only wrote each forms field parameters when the end user "saved" the form.
At the time, I was writing each form to a HDD flat file.

The nucleus of my system is a form field class. Each form field instance has an application wide unique name.

Recently, I added the Derby Database and now write each field to a Derby table when a form field looses the focus.
There is a Derby table for each form. The form Database tables host multiple form field instances.
I also have some utility methods that have the capability to change a form fields value via pre / post processor capabilities.

This, I thought, gave me persistence for the form data.
The application also maintains an embedded Address Book table and application controls required to reload the
form that had the focus when the application was terminated.

Still a "Work In Progress" but coming along nicely.

When I received the JavaRanch EMail about the "Pro JPA 2: Mastering the Java Persistence API" book and authors I read up some on JPA.
I researched JPA previously and decided that it was overkill for my stand alone application.

I just read a good article from java.sun.com that gives [I think] a nice overview of JPA
[http://java.sun.com/developer/technicalArticles/J2SE/Desktop/persistenceapi/] using baseball player / team entities.

JPA sounds great but do I need the JPA capability in my stand alone "Form Centric" Java app?

Regards,
Jim Crowell...