Replies: 1 comment
-
Official documentation on how drag and drop is done in GTK4: https://docs.gtk.org/gtk4/drag-and-drop.html A minimal java-gtk drag and drop example: package examples.dnd;
import ch.bailu.gtk.gdk.GdkConstants;
import ch.bailu.gtk.gio.ApplicationFlags;
import ch.bailu.gtk.gio.File;
import ch.bailu.gtk.gtk.Application;
import ch.bailu.gtk.gtk.ApplicationWindow;
import ch.bailu.gtk.gtk.DropTarget;
import ch.bailu.gtk.gtk.Label;
import ch.bailu.gtk.type.Str;
import ch.bailu.gtk.type.Strs;
public class DragAndDrop {
public final static Str ID = new Str("org.gtk.example.dnd");
public static void main(String[] args) {
var app = new Application(ID, ApplicationFlags.FLAGS_NONE);
app.onActivate(() -> {
// Get and initialize application window
var window = new ApplicationWindow(app);
window.setTitle("Drag and drop demo");
window.setDefaultSize(400,300);
// Create a label to display dropped files
var label = new Label("Drop files here");
label.setHexpand(true);
label.setVexpand(true);
// Crate drop target
var target = new DropTarget(File.getTypeID(), GdkConstants.ACTION_ALL);
target.onDrop((value, x, y) -> {
System.out.println("dropped");
var file = new File(value.getObject().cast());
label.setText(file.getBasename());
return true;
});
// Make the label a drop target
label.addController(target);
// Compose and display
window.setChild(label);
window.show();
});
System.exit(app.run(args.length, new Strs(args)));
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been trying to figure out how to do dnd with this, is there any way someone could give me an example or add an example demo for how to set it up? I am using it to move listboxrows around
Beta Was this translation helpful? Give feedback.
All reactions