Drag and Drop mit imageview

Hey Leute
ich weiss es ist viel text aber es wäre so coolwenn mir jemand helfen kann.

vor ein paar stunden habe ich schon etwas bezueglich drag and drop mit imageviews gefragt. nun habe ich auch mal angefangen und code angepasst, wo das drag and drop verfahren mit text gemacht wurde. soweit habe ich alles angepasst und finde auch alles ganz logisch aber es passiert einfach NICHTS :D ;(

In den meisten Beispielen wird die drag and drop methode in der "main" klasse gecoded. ich habe es aber nun im FXMLDocumentController gemacht (weil ich nicht hinbekommen habe den index der arrays dahin zu uebergeben :bahnhof:)

auf jeden fall habe ich nun die Methode Public void drag() geschrieben. meine Imagevies sind in einem tilepane und sollen in ein anderes pane gedropped werden. Ich habe ein Imageviewarray und ein panearray. beide unterstützen auch die drag and drop methoden.

das TARGET wird dann wohl das PaneArray sein und als SOURCE habe ich es mit dem TilePane selber und dem ImageviewArray versucht. doch wenn ich das Programm starte passiert einfach NICHTS wenn ich versuche irgendwas zu Draggen. ich denke das die Methode einfach nicht aufgerufen bzw benutzt wird oder ?

vll kann mir auch jemand sagen wie ich an die methode dran komme in der main klasse ? hier ist mal mein code und ein screenshot meinerapplikation

Main Methode:

Java:
public class Photoview extends Application {
    
    
    
   
    
    
    
    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        
        Scene scene = new Scene(root);
        
        stage.setScene(scene);
        stage.show();
       
        
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
}

Controller mit der drag methode:

Java:
public class FXMLDocumentController implements Initializable {
 

 String apiKey ="7a794d8692936b4b6371ad1750a617d2";
 String secret= "601e153ed7618eb4";
 
  ArrayList<String> Server = new ArrayList<>();
  String eingabe;
  PhotoList photoList;
  int i = 0;
   ImageView [] imageview;
  Image[] image;
  
  @FXML
  Pane pane1,pane2,pane3,pane4,pane5;
    
   final Pane collage2[]={pane1,pane2,pane3,pane4,pane5};
  
    @FXML
    Button ho;
      
    @FXML
    ImageView view;
    
    @FXML
    ScrollPane scroll;
    
    @FXML
    TilePane tile;
    
    @FXML
    TextField text;
    
    

    public FXMLDocumentController() {
      
    }
    
    
  
    
    @FXML
    private void handleButtonAction(ActionEvent event) throws FlickrException {
         
        Flickr flickr = new Flickr (apiKey, secret , new REST());
        eingabe = text.getText();
        SearchParameters searchParams = new SearchParameters();
        String[] tags = new String[]{eingabe};
        String  id = new String ();
        System.out.println(eingabe);
        
        searchParams.setSort(SearchParameters.INTERESTINGNESS_DESC);
        searchParams.setTags(tags);
        searchParams.setUserId(id);
      
        PhotosInterface photoInt = flickr.getPhotosInterface();      
        photoList = photoInt.search(searchParams,20,1);
        
        if(photoList!=null){
                //Get search result and check the size of photo result
                for( i=0;i<photoList.size();i++){
                   
                    //get photo object
                    Photo ph =(Photo) photoList.get(i);
                   
                   
                   Server.add(ph.getLargeUrl());
                   Image[] image = new Image [Server.size()];
                  
                   imageview = new ImageView [Server.size()];
                   image [i] = new Image(Server.get(i),true);
                   imageview[i]= new ImageView(image[i]);
                   imageview[i].setFitHeight(200);
                   imageview[i].setPreserveRatio(true);
                   imageview[i].setFitWidth(200);
                   
                   
                   tile.setPadding(new Insets(15, 15, 15, 100));
                   tile.setHgap(20);
                   tile.setVgap(17);
                   tile.getChildren().add(imageview[i]);
                   System.out.println(Server.get(i));
                   
          }
        }
    }
    
    
   public void drag(){
   
    imageview[i].setOnDragOver(event -> {
            Dragboard db = event.getDragboard();
            if (db.hasImage() || db.hasFiles()) {
                event.acceptTransferModes(TransferMode.COPY);
            }
        });
         
         imageview[i].setOnDragDetected((MouseEvent event) -> {
              /* drag was detected, start drag-and-drop gesture*/
              System.out.println("onDragDetected");
              
              /* allow any transfer mode */
              Dragboard db = imageview[i].startDragAndDrop(TransferMode.ANY);
              
              /* put a string on dragboard */
              ClipboardContent content = new ClipboardContent();
              content.getFiles();
              db.setContent(content);
              
              event.consume();
    });
          
          collage2[i].setOnDragOver((DragEvent event) -> {
              /* data is dragged over the target */
              System.out.println("onDragOver");
              
              /* accept it only if it is  not dragged from the same node
              * and if it has a string data */
              if (event.getGestureSource() != collage2[i] &&
                      event.getDragboard().hasFiles()) {
                  /* allow for both copying and moving, whatever user chooses */
                  event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
              }
              
              event.consume();
    });

        collage2[i].setOnDragEntered((DragEvent event) -> {
            /* the drag-and-drop gesture entered the target */
            System.out.println("onDragEntered");
            /* show to the user that it is an actual gesture target */
            
            
            event.consume();
    });

        collage2[i].setOnDragExited((DragEvent event) -> {
            /* mouse moved away, remove the graphical cues */
            
            
            event.consume();
    });
        
        collage2[i].setOnDragDropped((DragEvent event) -> {
            /* data dropped */
            System.out.println("onDragDropped");
            boolean success = true;
            /* if there is a string data on dragboard, read it and use it */
            /*  Dragboard db = event.getDragboard();
            
            if (db.hasImage()) {
            collage2[i].setString(db.getImage());
            success = true;
            }*/
            /* let the source know whether the string was successfully
            * transferred and used */
            event.setDropCompleted(success);
            
            event.consume();
    });

    }
   
   
   
   
   
   
   
   
 

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    
    
}


Meine FXML:

Code:
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" stylesheets="@../../style.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="photoview.FXMLDocumentController">
    <children>
      <ScrollPane fx:id="scroll" hbarPolicy="NEVER" layoutX="386.0" layoutY="239.0" prefHeight="542.0" prefWidth="848.0">
         <content>
            <TilePane fx:id="tile" prefHeight="542.0" prefWidth="846.0" />
         </content>
      </ScrollPane>
      <HBox prefHeight="216.0" prefWidth="1278.0" spacing="50.0">
         <children>
            <Pane id="pane1" prefHeight="200.0" prefWidth="200.0" stylesheets="@style.css" />
            <Pane id="pane2" prefHeight="200.0" prefWidth="200.0" stylesheets="@style.css" />
            <Pane id="pane3" prefHeight="200.0" prefWidth="200.0" stylesheets="@style.css" />
            <Pane id="pane4" prefHeight="200.0" prefWidth="200.0" stylesheets="@style.css" />
            <Pane id="pane5" prefHeight="200.0" prefWidth="200.0" stylesheets="@style.css" />
         </children>
         <padding>
            <Insets bottom="10.0" left="30.0" top="10.0" />
         </padding>
      </HBox>
      <SplitPane dividerPositions="0.5" layoutX="26.0" layoutY="238.0" orientation="VERTICAL" prefHeight="542.0" prefWidth="338.0">
        <items>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
               <children>
                  <VBox layoutX="4.0" layoutY="50.0" prefHeight="217.0" prefWidth="336.0" spacing="5.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="50.0">
                     <children>
                        <Label text="Tags:">
                           <font>
                              <Font name="Comic Sans MS Bold" size="26.0" />
                           </font>
                           <VBox.margin>
                              <Insets left="35.0" />
                           </VBox.margin>
                        </Label>
                        <HBox prefHeight="36.0" prefWidth="336.0">
                           <children>
                              <TextField fx:id="text" onAction="#handleButtonAction" />
                           </children>
                        </HBox>
                        <Label text="User-ID">
                           <font>
                              <Font name="Comic Sans MS Bold" size="26.0" />
                           </font>
                           <VBox.margin>
                              <Insets left="20.0" />
                           </VBox.margin>
                        </Label>
                        <HBox prefHeight="32.0" prefWidth="336.0">
                           <children>
                              <TextField />
                           </children>
                        </HBox>
                        <Label text="Zeitraum">
                           <font>
                              <Font name="Comic Sans MS" size="26.0" />
                           </font>
                           <VBox.margin>
                              <Insets left="20.0" />
                           </VBox.margin>
                        </Label>
                        <HBox prefHeight="100.0" prefWidth="200.0" spacing="120.0">
                           <children>
                              <ComboBox prefWidth="150.0" promptText="24 Stunden" />
                                <Button fx:id="button" onAction="#handleButtonAction" text="Click Me!" />
                           </children>
                           <opaqueInsets>
                              <Insets />
                           </opaqueInsets>
                           <VBox.margin>
                              <Insets />
                           </VBox.margin>
                        </HBox>
                     </children>
                  </VBox>
                  <VBox layoutX="85.0" layoutY="-3.0" prefHeight="51.0" prefWidth="336.0" AnchorPane.bottomAnchor="216.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                     <children>
                        <Label prefHeight="51.0" prefWidth="182.0" text="Bildersuche">
                           <font>
                              <Font name="Comic Sans MS Bold" size="26.0" />
                           </font>
                        </Label>
                     </children>
                     <padding>
                        <Insets left="80.0" />
                     </padding>
                  </VBox>
               </children>
            </AnchorPane>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
               <children>
                  <Label layoutX="67.0" layoutY="18.0" text="Bildbearbeitung">
                     <font>
                        <Font name="Comic Sans MS" size="26.0" />
                     </font>
                  </Label>
               </children></AnchorPane>
        </items>
      </SplitPane>
    </children>
</AnchorPane>

Ich hoffe sooooooooo sehr das mir hier irgendjemand helfen kann und bedanke mich schonmal im vorraus.

liebe grüße und einen schönen start in den tag
David
 

Anhänge

  • view.JPG
    view.JPG
    26,2 KB · Aufrufe: 32
Ähnliche Java Themen
  Titel Forum Antworten Datum
J Drag und drop aus einer JTable - bitte um Unterstützung AWT, Swing, JavaFX & SWT 2
G JPanel per Drag and Drop JButtons und Bilder ablegen AWT, Swing, JavaFX & SWT 1
AmsananKING ListView Drag And Drop AWT, Swing, JavaFX & SWT 0
AmsananKING Drag And Drop Filenames Inside A Listview AWT, Swing, JavaFX & SWT 1
DonBronson Java Graphics bewegbar machen (Drag&Drop) AWT, Swing, JavaFX & SWT 3
M Polygon per Drag&Drop verschieben AWT, Swing, JavaFX & SWT 26
Z Swing Drag and Drop mit einem JButton AWT, Swing, JavaFX & SWT 1
N Drag and Drop Fenster AWT, Swing, JavaFX & SWT 11
F Drag&Drop mit Transparenter Farbe bei PNG AWT, Swing, JavaFX & SWT 0
D JavaFX Pane per Drag&Drop bewegen? AWT, Swing, JavaFX & SWT 2
L JavaFX Drag and Drop funktioniert nicht AWT, Swing, JavaFX & SWT 3
J Drag and Drop von eigenen Objekten AWT, Swing, JavaFX & SWT 3
J Drag and Drop eines Buttons AWT, Swing, JavaFX & SWT 0
T Swing Drag and Drop für JComponents AWT, Swing, JavaFX & SWT 1
Z Swing Drag&Drop zwischen JTable und JTree AWT, Swing, JavaFX & SWT 4
F Drag und Drop AWT, Swing, JavaFX & SWT 0
L JavaFX JavaFX Chart Drag and Drop AWT, Swing, JavaFX & SWT 3
D JavaFX Drag&Drop mehrerer TreeViews oder TableViews AWT, Swing, JavaFX & SWT 1
P Drag & Drop zwischen Panels AWT, Swing, JavaFX & SWT 0
U Drag and Drop imageviews AWT, Swing, JavaFX & SWT 8
D SteelSeries in Netbeans als Drag-and-Drop einbinden AWT, Swing, JavaFX & SWT 0
C JTable Drag and Drop von Zeilen innerhalb einer Table AWT, Swing, JavaFX & SWT 2
S Swing Update eine JTabelle nach einer Drag&Drop Operation AWT, Swing, JavaFX & SWT 0
S Swing Suche Drag & Drop Beispiele AWT, Swing, JavaFX & SWT 1
A Drag and Drop mit JAVAFX- Scenebuilder AWT, Swing, JavaFX & SWT 1
R Performance Drag and Drop & Timer AWT, Swing, JavaFX & SWT 3
R Drag and Drop Problem auf Jpanel AWT, Swing, JavaFX & SWT 2
N Swing JTable und Drag und Drop AWT, Swing, JavaFX & SWT 2
A Drag and Drop eigener Objekte AWT, Swing, JavaFX & SWT 7
C Drag and Drop (inventar) AWT, Swing, JavaFX & SWT 15
F Swing Drag and Drop in JTree aus verschiedenen Listen AWT, Swing, JavaFX & SWT 6
T Swing JButton per Drag&Drop verschieben AWT, Swing, JavaFX & SWT 5
Iron Monkey JFileChooser - Drag and Drop AWT, Swing, JavaFX & SWT 5
Iron Monkey Nach Drag & Drop die Datei auf Komponent darstellen AWT, Swing, JavaFX & SWT 2
M AWT Drag n Drop-Support für Component AWT, Swing, JavaFX & SWT 5
HaukeG Swing Drag & Drop in verschiedenen Varianten AWT, Swing, JavaFX & SWT 4
S Swing Drag&Drop mit TransferHandler und JPanels AWT, Swing, JavaFX & SWT 8
C Swing Simulation von Drag and Drop Events AWT, Swing, JavaFX & SWT 3
H Swing "Drag and Drop" eines JComponent über ein JPanel AWT, Swing, JavaFX & SWT 2
R Drag 'n Drop AWT, Swing, JavaFX & SWT 3
S Selektion bei Drag&Drop AWT, Swing, JavaFX & SWT 4
C Swing Drag and Drop mit Objekten in einem Fenster. AWT, Swing, JavaFX & SWT 9
T SWT Drag&Drop: Eclipse FileTransfer mit Icons AWT, Swing, JavaFX & SWT 14
F Drag & Drop durch Verbindungslinien AWT, Swing, JavaFX & SWT 10
T Swing Drag and Drop - JLabels tauschen statt überschreiben AWT, Swing, JavaFX & SWT 11
S Drag and Drop über 2 Panels AWT, Swing, JavaFX & SWT 2
K JButtons innerhalb eines JPanels verschieben (DRAG&DROP) AWT, Swing, JavaFX & SWT 5
B Drag and Drop AWT, Swing, JavaFX & SWT 6
K Drag and Drop Workbench AWT, Swing, JavaFX & SWT 2
P SWT Eclipse Draw2D Drag and Drop (ruckelt) AWT, Swing, JavaFX & SWT 4
F SWT Drag and Drop im TreeViewer AWT, Swing, JavaFX & SWT 4
B Swing Drag&Drop mit Feedback (Image am Mauszeiger) AWT, Swing, JavaFX & SWT 7
Spin JFrame/ Frame Drag and Drop AWT, Swing, JavaFX & SWT 13
A TransferHandler & Drag n' Drop AWT, Swing, JavaFX & SWT 2
R Drag an Drop JTable Zelle AWT, Swing, JavaFX & SWT 6
D Drag & Drop - node.isRoot AWT, Swing, JavaFX & SWT 3
E Swing Drag n Drop Verschieben von Labels o.ä. AWT, Swing, JavaFX & SWT 10
E Swing Beim Drag & Drop, Drag verbieten?! AWT, Swing, JavaFX & SWT 2
E JTree Autoscroll bei Drag and Drop AWT, Swing, JavaFX & SWT 4
F Swing Problem mit Drag&Drop in JTable AWT, Swing, JavaFX & SWT 4
C keine weiteren Events während Drag&Drop Operation möglich? AWT, Swing, JavaFX & SWT 5
E Drag&Drop zwischen 2 Listen AWT, Swing, JavaFX & SWT 5
0 Swing Drag n' Drop Bug wenn Source und Target gleiche Komponente? AWT, Swing, JavaFX & SWT 4
C Drag and Drop JPanel auf JPanel nach drop erneut verschieben? AWT, Swing, JavaFX & SWT 3
M Swing JTable Drag'n'Drop von Dateien AWT, Swing, JavaFX & SWT 3
M Drag and Drop: Quellfenster AWT, Swing, JavaFX & SWT 2
M Buttons per Drag & Drop im GridBagLayout verschieben AWT, Swing, JavaFX & SWT 6
M Swing JList > Drag & Drop AWT, Swing, JavaFX & SWT 2
C Drag an Drop vom JTree zur JTable AWT, Swing, JavaFX & SWT 4
Z Drag and Drop auf Application AWT, Swing, JavaFX & SWT 3
G Drag and Drop JTree to Canvas AWT, Swing, JavaFX & SWT 7
H Drag&Drop von JComponents AWT, Swing, JavaFX & SWT 6
G JTable drag and drop AWT, Swing, JavaFX & SWT 4
H Drag&Drop mit GWT AWT, Swing, JavaFX & SWT 8
B Swing Drag&Drop einzelner Zellen in einer JTable AWT, Swing, JavaFX & SWT 12
A Swing Drag and Drop TreeNode User Object AWT, Swing, JavaFX & SWT 3
P JList: Reihenfolge der Elemente per Drag'n'Drop ändern. AWT, Swing, JavaFX & SWT 9
K Swing Wie ändere ich die default action für Drag&Drop AWT, Swing, JavaFX & SWT 6
R JLayeredPane - Drag&Drop - mouseDragged AWT, Swing, JavaFX & SWT 6
C JTable mit RowSorter und Drag & Drop: Zeile verschieben AWT, Swing, JavaFX & SWT 4
V SWT TreeViewer Drag'n'Drop LocalSelectionTransfer AWT, Swing, JavaFX & SWT 10
R Swing JLayeredPane - Drag&Drop Positionen vertauschen AWT, Swing, JavaFX & SWT 3
F Drag & Drop mit eigenen Komponenten AWT, Swing, JavaFX & SWT 2
B SWT - Drag & Drop innerhalb einer Table AWT, Swing, JavaFX & SWT 3
S Drag'n'Drop AWT, Swing, JavaFX & SWT 8
E Drag&Drop JTable; Renderer füllt alle Zellen AWT, Swing, JavaFX & SWT 10
M Drag & Drop in Swing (createTransferable) AWT, Swing, JavaFX & SWT 6
T Drag Quelle beim Drop AWT, Swing, JavaFX & SWT 6
A Drag & Drop von Zeilen innerhalb einer Tabelle AWT, Swing, JavaFX & SWT 2
E Drag & Drop von jTree in JList AWT, Swing, JavaFX & SWT 5
P Dateien per Drag&Drop ins Java-Fenster ziehen AWT, Swing, JavaFX & SWT 8
G JTree Node ggf. aufklappen bei Drag & Drop? AWT, Swing, JavaFX & SWT 7
J Drag'n Drop imm selben Frame unterbinden AWT, Swing, JavaFX & SWT 3
S Table Row per Drag and Drop in andere Table schieben? AWT, Swing, JavaFX & SWT 14
X wiedermal Drag n Drop AWT, Swing, JavaFX & SWT 2
P Drag & Drop AWT, Swing, JavaFX & SWT 2
X Drag and Drop AWT, Swing, JavaFX & SWT 2
F Drag&Drop Jlist -> JList AWT, Swing, JavaFX & SWT 3
G Drag and Drop mal wieder? AWT, Swing, JavaFX & SWT 2
G Drag And Drop von Component (List, Tree) zum Desktop AWT, Swing, JavaFX & SWT 2

Ähnliche Java Themen

Neue Themen


Oben