Swing drag and drop [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to implement a game board in swing (needs to be a table, though about either jtable or gridlayout etc ...) where I will be able to drag and drop a picture on to this game board and all the cells that the picture fell on will get a notification that they were chosen.
Can anyone help with that? how do I get a couple of cells in a table know that an object was dropped on them?

Have a look at this tutorial.

I think you have to spent some time with Google. I found the following with a little time with Google.
Introduction to DnD
How to drag and drop with Java 2, Part 1
How to drag and drop with Java 2, Part 2
Drag and Drop Effects
Hope this helps :)

Read this and if you have an more specific questions come back and ask them.

Related

Is it possible to put a button in a NatTable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
enter image description here
Is it possible to put a button in the table like the attached image?
NatTable is a custom painted table control. Putting real buttons in the table is possible, but actually does not really make sense and could even lead to resource issues in larger tables.
You can actually render anything if you have a corresponding painter. And for a button you of course also need the action binding. NatTable has the ButtonCellPainter to render a cell as a button. But actually the implementation to mimik the button press is a bit outdated IMHO. The corresponding example should give you an idea what you can do and how to do it.
https://git.eclipse.org/c/nattable/org.eclipse.nebula.widgets.nattable.git/tree/org.eclipse.nebula.widgets.nattable.examples/src/org/eclipse/nebula/widgets/nattable/examples/examples/_102_Configuration/Rendering_cells_as_a_link_and_button.java

How can I create a clickable grid in java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm creating Conway's game of life in java, and I want to make a clickable on screen grid to toggle the cells on/off before pressing start. What is the best way to do this? A grid of JButtons won't do it for me as it looks horrible (unless theres a way of changing how they look?)
any help is greatly appreciated - thanks!
I would use raw graphics 2D draw commands to manually draw rectangles in AWT for Conway's Game of Life. You can still listen to click events for the frame and then use the x and y coordinates to calculate the cell. It will be a lot faster than using UI components, as well.

Move images on JPanel in Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to place some images on a JPanel and make them "relocatable" so I can click on one of the images and move to somewhere else on the JPanel while holding the button. It works fine with one image but I just can't come up with a solution for more images than one. I have checked many examples and tried many different ways. If you have any idea please share with me. Thanks!
It works fine with one image but I just can't come up with a solution for more images than one.
You can use the Component Mover. You register the component with the class and then you can move any component.
Or if you don't need the full features of the ComponentMover class you can just use the basic listener for dragging a component.

How to add Interactive animations in jFrame? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I need to develop a Java programe using NetBeans. And In a JFrame I need to add a a image of planetary system and when the user sets a date and a time, Planets should rotate to their relevant positions. I don't have any idea about this yet. What is the possible way to do this? Please tell me soon
There are literally dozens of ways this might be achieved.
You could use:
Swing Timer
The Timing Framework
Trident
java-universal-tween-engine
The last three are animation engines. Personally, I use the Timing Framework, but that's more to do with what I'm familiar with and my needs at the time.
You'll probably need to do a lot of custom painting to get this to work, take a look at:
Custom Painting
2D Graphics
For more details

Animated drag and drop in JTable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Do you know some way to make drag and drop in table more user-friendly? For example: row stick to mouse on drag, and other rows swap places when dragging. Can you recommend me some library for this ?
I'd suggest you take a little time to have a read through The Rabbit Hole which has some excellent articles on the topic of drag'n'drop.
These are most of the articles of interest
Smooth JList Drop Target Animation
Smooth Tree Drop Animation
My Drag Image is Better than Yours
Dead Simple Drags
Fancy Drops
Drag Images for Everyone
Drop Target Navigation, or you drag your bags, let the doorman get the door
Swing Drag Images (Improved)
Well, Java libraries are usually not good really at the "animation" thing. There is a way to do this using the D and D libraries Java comes with but it would require swapping the values of the rows, rather than swapping the rows themselves.
Java is very limited at this kind of stuff. Either you hard code your own library, or use some other language that has libraries for tasks like these.

Categories