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
;(
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:
Controller mit der drag methode:
Meine FXML:
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
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
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