Well im still stuck on this dang DnD stuff. Here is a working class that I am trying to implement (take the right peices from) to make my DnD work correctly from label fields (equiped area) to a list (inventory) area. Ive got over the following class for days now and tried a couple of different things but need some help understanding whats exactly going on in it to see what i need and how to do it.

//Create the equipable plane to show in appletJPanelinvEquipPanel = newJPanel();invEquipPanel.setLayout(newGridLayout(6,1));TitledBorderinvEquipPanelTitle = BorderFactory.createTitledBorder("Equipped");//Add items to the planeinvEquipPanel.add(invHelmetPanel);invEquipPanel.add(invArmorPanel);invEquipPanel.add(invMainHandPanel);invEquipPanel.add(invOffHandPanel);invEquipPanel.add(invAcc1Panel);invEquipPanel.add(invAcc2Panel);invEquipPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));invEquipPanel.setPreferredSize(newDimension(300, 480));invEquipPanel.setBorder(invEquipPanelTitle);

//At this point we use the same code to retrieve the data//locally or serially.

//We'll drop at the current selected index.intindex = target.getSelectedIndex();

//Prevent the user from dropping data back on itself.//For example, if the user is moving items #4,#5,#6 and #7 and//attempts to insert the items after item #5, this would//be problematic when removing the original items.//This is interpreted as dropping the same data on itself//and has no effect.if (source.equals(target)) {if (indices != null && index >= indices[0] - 1 &&index <= indices[indices.length - 1]) {indices = null;returntrue; } }

didn't really have time to clean it up I was away for a long weekend, it should give you an idea of how it could work. I would also note that perhaps its better to avoid serialised variants sine you rather not want ppl dragging items from one app to an other.

also note how the remove on the inventory isn't correct (the Item gets lost now, it should return to the Inventory(List)), and how the view and the model are unnessasery tangled up, perhaps there should be an CharacterSheetModel etc etc. oh well thats what revisions are for.

/** * Indicates that a method declaration is intended to override a * method declaration in a superclass. If a method is annotated with * this annotation type but does not override a superclass method, * compilers are required to generate an error message. * * @author Joshua Bloch * @since 1.5 */

Can you help me understand the model(item) stuff that you are doing throughout your classes. I believe it is simply turning it all to text. But I can't quite figure out where to put that and where to modify a transfer handler to fit my existing classes for equipment and such. Im trying to keep the already made look and feel and implement your drag and drop transfer logic.

as it is now the Item is simply a wrapper for a String. if you wanted to assosiate an image for it simply added to Item and adapt/change de (cell)renders to use it. the Item is a POJO you can simply subsitute it with your current Item class. all you need to do then is to alter your renders to call the right methodes so they show what you want to show.

Item(model) -> ItemView(view)

if you would create a view(Object) for every item beeing displayed it would cause performance issues. instead we use 1 view and 'plug' the model into it. (creating a flywaight pattern) the flywaight class is ItemViewRenderer . also have a look at Custom renderers in the swing tutourial.

but yes its all turning it into text. As the DefaultRenderer does, only that calls toString() or String.valueof() rather. its just easely extended like this, and you save the toString() for displaying something more usefull.

For example I have a constants or DB access class. it has Sword, Armor, Ring.

In the database these are lines like. Sword +1atk +1dmg such and so forth.

If i input the "Sword" as a string value given the Item Model, can I in the Item Model convert that or associate that with an image that holds the same placer and characteristics. So instead of selecting the text "Sword" from the JLabel and dragging back and forth to the list I can click, hold, drag a Sword image.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org