JavaFX 2:扩展和折叠时树视图中的奇怪行为(Javafx 2.2中可能存在错误)

时间:2014-10-03 06:32:50

标签: java javafx-2

我正在使用TreeView,但我看到了一个奇怪的行为。首先看一下这里的代码

FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import com.nuaxis.rpas.client.contol.*?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.main.FXMLController">
<top>
  <MenuBar BorderPane.alignment="CENTER">
    <menus>
      <Menu mnemonicParsing="false" text="File">
        <items>
          <MenuItem mnemonicParsing="false" text="Close" />
        </items>
      </Menu>
      <Menu mnemonicParsing="false" text="Edit">
        <items>
          <MenuItem mnemonicParsing="false" text="Delete" />
        </items>
      </Menu>
      <Menu mnemonicParsing="false" text="Help">
        <items>
          <MenuItem mnemonicParsing="false" text="About" />
        </items>
      </Menu>
    </menus>
  </MenuBar>
</top>
<bottom>
  <AnchorPane prefHeight="15.0" prefWidth="600.0" BorderPane.alignment="CENTER" />
</bottom>
<center>
  <SplitPane fx:id="mSplitPane" prefHeight="160.0" prefWidth="200.0" BorderPane.alignment="CENTER">
    <items>         
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
           <children>
              <Button layoutX="167.0" layoutY="76.0" mnemonicParsing="false" onAction="#onBAction" text="Button" />
           </children>
      </AnchorPane>
    </items>
  </SplitPane>
</center>
</BorderPane>

MainApp

public class MainApp extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));

        Scene scene = new Scene(root);

        scene.setFill(Color.LIGHTGRAY);
        stage.setTitle("Tree View");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }   
}

FXMLController

public class FXMLController  {

    @FXML  private SplitPane mSplitPane;
    TreeItem<String> rootNode;

    @FXML
    public void initialize() {

        rootNode = new TreeItem<>("asdf");
        rootNode.setExpanded(true);
        TreeItem<String> groupNode = new TreeItem<>("645654");
        groupNode.getChildren().addAll(new TreeItem<>("adsad"),
                new TreeItem<>("dfsf"),
                new TreeItem<>("sdfdsf"));

        rootNode.getChildren().addAll(new TreeItem<>("565y"),
                groupNode,
                new TreeItem<>("fdgfdhtry"),
                new TreeItem<>("dgfdgdftg"));
        TreeView<String> list = new TreeView<String>(rootNode);
        list.setShowRoot(false);
        mSplitPane.getItems().add(0, list);
    } 

    @FXML
    void onBAction(ActionEvent event) {
        rootNode.getChildren().add(new TreenItem<>("new"));
    }
}

解释

使用JDK 1.7.0_67和JavaFX v 2.2 请参阅附图,我执行了5个步骤,这给出了奇怪的行为。解释出现在图片中。如果这不是bug那么我该如何解决这个问题。 我也在JDK 8上查看了这个,但它在jdk 8中不存在。但是我们不能将我们的项目从JDK 7移到JDK 8.

Steps Which I performed and seems like it is bug

0 个答案:

没有答案