Hatena::ブログ(Diary)

Real Kaiji, lol.

2018-01-07

Add to AnchorPane

//Open new tab and connect FXML

Yesterday, trial to create new tab succeeded. Next, I need to set contents into the opened tab.
I made "tabs.class" extends Tab class, and create "listTab.class" as subclass derived from "tabs".
"tabs.class" has method to instantiate root from FXML. So when "listTab.class" is called, I can open the new tab with only String value to set title.
However, I couldn't run it right. I saw many valous error code. It told me it couldn't instantiate, not load root, not get a pointer, or not exist class.
Finally what lead me to success is to write the code in FXML, that is "fx:root". "fx:root" is necessary to get object as root when load FXML. It has a function to connect controller to FXML.

//TreeView

I made TreeView to show file split to day by day. It had gone right earlier than when I made TableView.
As same as TableView, it would be build by reading csv file in for(){} roop. The first line of that file is set title might be number of year and month. So for() roop starts at not 0 but 1.
Additionally, when I add node in the tree, I have to avoid adding same named node. For example, first column of file is number of date, second column is what day of week it is. If all of them is shown in the tree, I wonder it looks like very complecated. To avoid it, wrote if-sentence in the roop. I get a value of last process befobre setting new value, and compare new value of first column and last value.
If those two values are same, add only third column that is final column in the tree, but it will instantiate new value of first column.
When I tried to show it, I took many many times. Finally I found how it will be shown, that is adding to AnchorPane.

//MenuBar

Making MenuBar was kinda easy for me. I made a lot of little mistake, though lol. It is only just adding to Pane as same as when I show TreeView, but I had not noticed that I add to another Pane, lol.
These are miss code when I can't.
f:id:rko8356:20180108050527p:imagef:id:rko8356:20180108050523p:image

<AnchorPane fx:id="topAnc"  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ctrl.Controller">
   <children>
      <Button fx:id="newTab" mnemonicParsing="false" onAction="#getNewTab" text="New Tab" />
      <MenuBar fx:id="menuBr" layoutY="2.0" AnchorPane.topAnchor="2.0" />
      <ScrollPane layoutY="25.0">
         <content>
          <AnchorPane fx:id="trAnc">
               <children>
                  <TreeView fx:id="trvFld" />
                  <Label />
               </children>
            </AnchorPane>
         </content>
      </ScrollPane>
      <TabPane fx:id="tabFld" layoutX="140.0" layoutY="25.0" tabClosingPolicy="UNAVAILABLE" />
   </children>
</AnchorPane>

Allit took was adding menuBr to topAnc.