是什么导致JavaFX 2.0重新绘制GUI?

时间:2012-03-25 11:27:04

标签: java swing user-interface javafx-2

我刚开始使用JavaFX而且我很难从Swing转换过来:当我在Swing中编写时,我可以通过调用repaint()来重新绘制GUI但我无法想象如何在JavaFX中执行此操作?

我有一个BorderPane我交换了一个不同的HBox以响应用户操作。当我调试它并遵循它的功能时,看起来它正在完全按照我的要求执行:新的HBox已经创建并通过BorderPane添加到setBottom()但是在方法返回后我仍然得到原始的窗格中的框。 IE,GUI没有重新绘制。我确信这是基本的,但令人沮丧。 :)

示例:

public class MainFrameNode extends BorderPane{

MessageVBox messageBox = new MessageVBox();
ScrollPane sp = new ScrollPane();

public MainFrameNode(){
    setPrefSize(600, 700);
    setBottom(new ButtonsHBox());

    sp.setContent(messageBox);
    sp.setHbarPolicy(ScrollBarPolicy.NEVER);
    sp.setVbarPolicy(ScrollBarPolicy.ALWAYS);
    setCenter(sp);
}

    public void setBottomBox(Node box){
        //AgentTester.getRoot().getChildren().remove(0);
        setBottom(box);
        //AgentTester.getRoot().getChildren().add(this);//AgentTester.getMainFrame());
}

在这个例子中,我有一个BorderPane,它的底部窗格中有一个HBox。我想将HBox替换为不同的HBox,然后重新绘制gui。我可以使用两个注释掉的行来删除并重新添加整个Broder窗格(虽然这看起来有其自身的问题)但是如果我只使用setBottom()则gui不会重新绘制。希望这有助于澄清我的问题。

使用MainFrameNode的代码也非常基本:

    public void start(Stage arg0) throws Exception {

    final MainFrameNode mainFrame = new MainFrameNode();
    instantiateClient(mainFrame.getMessageBox());
    root.getChildren().add(mainFrame);
    Scene scene = new Scene(root);
    arg0.setScene(scene);   
    arg0.setOnHiding(new EventHandler<WindowEvent>(){
        public void handle(WindowEvent e){
        System.exit(0);
        }
    });
    arg0.show();
}

0 个答案:

没有答案