我遇到了TextArea的一些问题。 我按下按钮后尝试设置新文本。 但GUI不是新文本。如果我使用get Text()检查textarea,控制台将显示新文本。所以View类可能存在问题..
希望你们能帮帮我。
Little Codeexplaining: Class Main FDSAPP正在使用StartView启动App。从StartView我切换到NewPCapView并编辑一些东西。因此,当我按下Apply时,protocollTextArea中的文本应更改为“Pcap created and saved ......”
以下是代码:
public class View{
...
public TextArea mainTextArea = new TextArea("--Framework Data Streams--\n
--A Framework to create and to merge Pcaps :D--"),
protocollTextArea = new TextArea("Just showing what you did");
...
}
public class NewPCapView extends View{
...
public void init(){
...
//alle Listener
apply.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
applypressed = true;
try {
String filename = "InhaltOwnPCap.xml";
that.getControl().makeXMLFromOwnPcap(filename);
that.getControl().getContentFromXMLForOwnPcap(filename);
that.closeSecondStage();
protocollTextArea.setText("Pcap created and saved
under C://Temp/outputfile.pcap");
that.primaryStage.toFront();
System.out.println(protocollTextArea.getText());
}catch (XMLStreamException | FileNotFoundException e) {
e.printStackTrace();
}
}
});
...
}
public class StartView extends View{
...
/**
* Listener
*/
public void initListener(){
...
createOwnPCap.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
that.makePCapViewUI();
}
});
}
public void initCenter(){
hBox1 = new HBox();
mainTextArea.setMinWidth(600);
mainTextArea.setEditable(true);
textAreaCSS(mainTextArea);
hBox1.getChildren().add(mainTextArea);
}
....
public void initRight(){
vBox = new VBox();
protocollTextArea.setEditable(false);
protocollTextArea.setWrapText(true);
Label protokoll = new Label("Protocoll: ");
Button save = new Button("Save");
//Bereich Protokoll
protokollCSS(protokoll);
//Bereich TextArea
textAreaCSS(protocollTextArea);
//Speichern fehlt noch
vBox.getChildren().addAll(protokoll,protocollTextArea,save);
}
/**
* Helpingmethods
*/
public void protokollCSS(Label protokoll){
protokoll.setStyle("-fx-border-color: grey; "
+"-fx-border-width: 1;"
+"-fx-background-color: white");
}
public void textAreaCSS(TextArea textArea){
textArea.setPrefRowCount(20); textArea.setPrefColumnCount(25);
textArea.setStyle("-fx-border-color: grey;"
+"-fx-border-width: 1");
}
...
}
public class FDSApp extends Application {
private FDSApp that = this;
public Stage secondStage;
public Stage primaryStage;
public BorderPane root;
private StartView startView;
private NewPCapView pCapView;
private Controller controller;
private Scene mainScene = null;
@Override
public void start(Stage stage) throws Exception {
this.primaryStage = stage;
root = new BorderPane();
startView = new StartView(that);
pCapView = new NewPCapView(that);
controller = new Controller(that,pCapView);
initUI(primaryStage);
}
public void initUI(Stage primaryStage){
//Fenster konfigurieren und anzeigen
primaryStage.setTitle("...");
primaryStage.setResizable(false);
//Hintergrund
root.setStyle("-fx-background-color: lightsteelblue");
root.setTop(startView.getHBox());
root.setCenter(startView.getHBox1());
root.setLeft(startView.getHBox2());
root.setRight(startView.getVBox());
Scene mainScene = new
Scene(root,startView.getWidth(),startView.getHeight());
primaryStage.setScene(mainScene);
primaryStage.show();
}
public void makePCapViewUI(){
primaryStage.toBack(); //Macht die Primary invisible
secondStage = new Stage();
secondStage.setTitle("Creating PCap");
secondStage.setScene(pCapView.getPCapScene());
secondStage.show();
}
....
}