Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag and Drop cannot access inside content  RSS feed

 
Bogdan Pop
Greenhorn
Posts: 4
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bogdan Pop
Greenhorn
Posts: 4
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!