jQuery in Action, 2nd edition
The moose likes Swing / AWT / SWT and the fly likes Drag and Drop cannot access inside content Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Drag and Drop cannot access inside content" Watch "Drag and Drop cannot access inside content" New topic
Author

Drag and Drop cannot access inside content

Bogdan Pop
Greenhorn

Joined: Jul 04, 2011
Posts: 4

Hi everyone,

I have a request in my project to implement draggable panels that contain buttons inside.

I have followed the guidelines from the official tutorial ( http://download.oracle.com/javase/tutorial/uiswing/dnd/index.html ). The panel definition extends JPanel and implements the Transferable interface. The panels are contained in a JList that has the draggable functionality enabled, and custom cell renderer and transfer handler attached. The drag and drop is working well, no problems here.

The problem that I have is that I do not have access to the elements inside the panel components. More specifically, I cannot interact with the buttons inside the panels (click/highlight), I can just drag them around.

I have implemented a custom MouseInputAdapter to echo intercepted events for the panel and the list, and the events are only intercepted at the list level, they do not get to the panels, or to the buttons inside the panels.

Is there any way to access the inside elements of my list and click on the buttons?

Thank you in advance,
Bogdan.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Bogdan Pop wrote:I have followed the guidelines from the official tutorial ( http://download.oracle.com/javase/tutorial/uiswing/dnd/index.html ). The panel definition extends JPanel and implements the Transferable interface. The panels are contained in a JList that has the draggable functionality enabled, and custom cell renderer and transfer handler attached. The drag and drop is working well, no problems here.

The problem that I have is that I do not have access to the elements inside the panel components. More specifically, I cannot interact with the buttons inside the panels (click/highlight), I can just drag them around.


I don't understand the problem. Perhaps I don't understand what part of the code is the "I" which you say cannot interact with the buttons. Is the problem that the user can't interact with the buttons while he or she is dragging the panel containing them? Or that the user can't interact with the buttons after having dragged them? Or that the user can't ever interact with the buttons?
Bogdan Pop
Greenhorn

Joined: Jul 04, 2011
Posts: 4

The user can't ever interact with the buttons.

The result I am looking for is that the user can click on the inside buttons (not working now), or the user can drag and drop the panels (working).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

If you're working with drag-and-drop then surely you must be able to write basic code which puts buttons in panels? I'm assuming that's the case. Which means you must have done something different here. I would suggest starting with the basic code and working from there.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4167
    
    3

The panels are contained in a JList ...
...
I have implemented a custom MouseInputAdapter to echo intercepted events for the panel and the list, and the events are only intercepted at the list level, they do not get to the panels, or to the buttons inside the panels.

Don't confuse a renderer with a component added to a visible hierarchy. Recommended reading:Concepts: Editors and Renderers. Yes, I know it's part of the JTable tutorial but the renderer concept applies equally to JList (and also JTree and JComboBox).

edit Also note that this has nothing to do with DnD.


luck, db
There are no new questions, but there may be new answers.
Bogdan Pop
Greenhorn

Joined: Jul 04, 2011
Posts: 4

Thank you for the replies Darryl and Paul.
It is indeed not related to the drag and drop. I deactivated the drag and drop from the list and the problem remains.
I will have a look into the documentation related to Renderers and try to enhance my list cell renderer.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4167
    
    3

I will have a look into the documentation related to Renderers and try to enhance my list cell renderer.


Any amount of enhancing won't convert a renderer into an editor. To get something like an editable JList, use a single-column JTable.
Bogdan Pop
Greenhorn

Joined: Jul 04, 2011
Posts: 4

Darryl Burke wrote:
I will have a look into the documentation related to Renderers and try to enhance my list cell renderer.


Any amount of enhancing won't convert a renderer into an editor. To get something like an editable JList, use a single-column JTable.


Thanks again Darryl, I will try to implement this approach.
Charles Van Damme
Greenhorn

Joined: Feb 24, 2009
Posts: 12
Hello, are you still looking to this discussion ?
On july 5th, 2011, Darryl Burke was so kind as to answer:
Any amount of enhancing won't convert a renderer into an editor. To get something like an editable JList, use a single-column JTable.

But on july 4th, he also wrote:
Recommended reading:Concepts: Editors and Renderers. Yes, I know it's part of the JTable tutorial but the renderer concept applies equally to JList (and also JTree and JComboBox).
, meaning that you can attach a Renderer and an Editor to a JList's cell as well as to a JTable's cell.
So, can anybody explain why Darryl Burke advices to use a 'single column JTable' instead of a JList to get an editable JList ?
I need to have an editable JList (or JComboBox) enabling the GUI user to edit and erase items, and above all to make simple selection of string, like with a combo box, to pass it on to another JComponent.
Thanks to give me tips to achieve that goal.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4167
    
    3

Charles Van Damme wrote:Hello, are you still looking to this discussion ?
On july 5th, 2011, Darryl Burke was so kind as to answer:
Any amount of enhancing won't convert a renderer into an editor. To get something like an editable JList, use a single-column JTable.

But on july 4th, he also wrote:
Recommended reading:Concepts: Editors and Renderers. Yes, I know it's part of the JTable tutorial but the renderer concept applies equally to JList (and also JTree and JComboBox).
, meaning that you can attach a Renderer and an Editor to a JList's cell as well as to a JTable's cell.

Read more carefully. I clearly said that the renderer concept applies equally to JList. Not the editor concept.


Charles Van Damme wrote:So, can anybody explain why Darryl Burke advices to use a 'single column JTable' instead of a JList to get an editable JList ?
I need to have an editable JList (or JComboBox) ...

JComboBox can be editable. Read the API and follow the link to the tutorial on How to Use Combo Boxes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drag and Drop cannot access inside content
 
Similar Threads
Learning to use Drag and Drop
Drag and drop over an iframe
gwt drag and drop problem
same old gridbag
Can't Focus On JPanel