• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Drag and Drop

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am designing a frame for managing batches of items. Each batch contains 10 items and the frame needs to allow them to drag and drop items between batches. There will be a lot of comparing and contrasting so the ability to move the batches around the screen is also required. Initially the frame will load batch 0 (which is always present). The user can then choose from a combobox which other batches they want to view. They can open several at a time and drag and drop between any of them. I've attached a diagram which may help to explain.

What is the best way to do this?

Options I've thought about:
1. JTables. Each batch is a JTable. When I put a JTable on the screen, I can't move it around. Is this possible?
2. Buttons. Each item is abutton enclosed in something like a JPanel. Keeping the buttons aligned maybe an issue.

As you can see I'm hitting issues no matter which way I go so I wondered if there is a better design that would be simpler to implement. All suggestions welcome!
WranglerDes.jpg
[Thumbnail for WranglerDes.jpg]
 
Marshal
Posts: 72905
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never seemed to be able to get drab'n'drop to work. Have you considered a combo box, where you can highlight several items? You can use a button to move them. I think you shouldn't worry about alignment until yu have your functionality working.

Adding you to our GUIs forum.
 
Saloon Keeper
Posts: 23689
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this might be a good start: https://docs.oracle.com/javase/tutorial/uiswing/dnd/intro.html

Notice that they are sourcing from a JList control. And while they're not doing so in their examples, you should be able to drag to and drop into a destination JList. And vice versa, if you like. This kind of behavior is part of some UI/UI extension widget sets including RichFaces for JavaServer Faces and I'm virtually certain also in at least one JavaScript toolkit (too many to choose from!)

Alas, it's not a standard control in Swing, but it shouldn't be that hard.

As far as DnD works, you basically have 3 types of events:

1. User presses and holds mouse drag button - usually left-mouse - down, signalling start. You may do a multi-select here by using a modifier (additive) key and/or rubber-banding before formal dragging begins.

2. User moves mouse while continuing to hold the "drag" button. Mouse movement events are reported.

3. User releases mouse drag button. If the mouse pointer is over a drop target, then a "drop" event is signalled.
 
Rancher
Posts: 3241
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For each batch I would create a JPanel with:

1. a JLabel for the batch number
2 a JList (in a JScrollPane) for the details.

Then you can add a MouseListener to the panel to enable dragging of the panel around the screen.

Check out the Basic Dragging example code found in Moving Windows
 
Neil Barton
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys,
That's excellent. I'll go and investigate the JList idea.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic