2016-05-03 8 views
0

Ich habe gesucht und keine Antwort gefunden. Ich habe eine Schriftrolle, eine Schaltfläche und ein Textfeld. Wenn ich den Knopf drücke, nehme ich den Wert in der Textfläche, dann möchte ich den Text oben rechts in scrool setzen, wenn ich noch einmal nach unten gehe und so weiter. Beispieljava fx Element hinzufügen ScroolPane


        hello guys 
            this is my label 

Textbereich Taste

das ist mein fxml Datei

<AnchorPane id="AnchorPane" prefHeight="392.0" prefWidth="357.0"  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="indixischat.ChatController"> 
    <children> 


    <Pane id="title" layoutX="14.0" layoutY="14.0" prefHeight="60.0" prefWidth="333.0" /> 
    <TextField fx:id="text" layoutX="14.0" layoutY="362.0" prefHeight="17.0" prefWidth="299.0" /> 

    <Button fx:id="sendMessage" onAction="#sendMessage" layoutX="318.0" layoutY="365.0" mnemonicParsing="false" prefHeight="11.0" prefWidth="29.0" text="Button" /> 
    <ScrollPane fx:id="scroll" layoutX="14.0" layoutY="44.0" prefHeight="319.0" prefWidth="339.0"> 
    <content> 
     <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="412.0" prefWidth="326.0" /> 
    </content> 
    </ScrollPane> 

+0

die scrool Aufrechterhaltung offensichtlich –

Antwort

0

Sie einen VBox als Container verwenden können die Texte in der ScrollPane. Dann auf jeder Button klicken Sie einen neuen TextField- erstellen und hinzufügen, dass auf die VBox:

public class Test extends Application { 

    @Override 
    public void start(Stage primaryStage) { 

     TextField txtInput = new TextField(); 

     VBox boxTextFields = new VBox(); 
     boxTextFields.setAlignment(Pos.TOP_RIGHT); 
     boxTextFields.setFillWidth(false); 

     ScrollPane scrollPane = new ScrollPane(boxTextFields); 
     scrollPane.setFitToWidth(true); 

     Button button = new Button(); 
     button.setOnAction(e -> boxTextFields.getChildren().add(new TextField(txtInput.getText()))); 

     VBox root = new VBox(textField, button, scrollPane); 
     root.setAlignment(Pos.TOP_CENTER); 

     primaryStage.setScene(new Scene(root, 300, 300)); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
}