Real Kaiji, lol.


Controll width of tablecolumn automatically

I need so long time to resolve the problem that I can't adjust each width of tablecolumns.
When I splead a window, they should keep their width. So I tried some ways with googling.
One way is to use method getWidth() and setPrefWidth(). But this way did not run with showing me NullPointerException. Because tableview instance returns null as its property of width.
I wrote some method to controll width of tablecolumn, but it returned 0 so columns appeared as no width.
This is the code.

parCtrl.java (SuperClass of tabControll)

void setPW(TableView tv,TableColumn tc, double p) {
void setMxW(TableColumn tc, double w) {


public void initialize(URL url, ResourceBundle rb) {
	setCW(noCol, 0.075);
	setCW(inTimeCol, 0.1);
	setCW(outTimeCol, 0.1);
	setCW(numCol, 35/600);
	setCW(mfCol, 0.05);
	setCW(accCol, 0.05);
	setCW(callCol, 0.15);
	setCW(amoCol, 2/15);
	setCW(cardCol, 2/15);

void setCW(TableColumn tc, double p) {

This code runs such as this.

Not only columns are invisible but also Amounts label is showing 0 as tableview's prefWidth.

The other way is to create the instance of TableColumn and then set property of width without coding in FXML.
I wondered I cannot change property already desided. So I create TableColumn instances one by one.


private TableColumn noCol = new TableColumn("No.");
private TableColumn inTimeCol = new TableColumn("InTime");
private TableColumn outTimeCol = new TableColumn("OutTime");
private TableColumn numCol = new TableColumn("Num");
private TableColumn mfCol = new TableColumn("M/F");
private TableColumn accCol = new TableColumn("Acc");
private TableColumn picCol = new TableColumn("PIC");
private TableColumn callCol = new TableColumn("Call");
private TableColumn amoCol = new TableColumn("Amount");
private TableColumn cardCol = new TableColumn("Card");

I had gone success when I wrote method "setPrefWidth()" with own values each columns.
But when I gave to setPrefWith() the valuable as argument, it did not run.
Perhaps, it is because of value returned by getWidth() method. AnchorPane is set its own width property by FXML, and TableView is anchored as if adjusting its width depending on size of AnchorPane.
However getWidth() method returned 0 whenever it ran.

Finally I get a way to adjust columns by reading refurence of Oracle official HP.
TableView has the status that is called ColumnResizePolicy.
When it is CONSTRAINED_RESIZE_PPLICY, columns in that table are made to resize to fit width of the table.



This code shows

See you.



//getController in Main.class returns null.

Too many times has past since I found that problem.
Another class cannot call Controller class's method by static valuable in Main.class.
Result when it runs, valuable is retured as null.
But when another controller calls, it returns controller instance correctly.
According to my thought from those results, I guess that not only instance of controller but also other fields cannot store whatever.
So I must code controller's method to controll itself in itself.q

//Comparing between String type values.

I had never known how I compare between String type values. I had always use comparison operator "==" when I need to compare String types. Today, I got across NullPointerException when it ran.
On close inspection about that, I must not use "==" and should use equal() method.
If value will be compared is not primitive type, how "==" compares values is comparing at value of instance itself. And if the instances compared are different when that process is running, "==" returns false even if finally they return same value.
In contrast, equals() method compares between final values of those instances. So if one of them is not null, it returns boolean I want.

There are all of what I learned.
See you.


Create save data

This is the process for saving data in app I thought up.
The app I'm making has functions to show separated data on own tab. For the sake of showing that separated data, I created the "db" class. "db" class is the superclass of all class have separated data.
And "db" class has all its data in the own 2-dimentional array. Next, "save" class that run to manage the all data by setting value of each instance into its 3-dimentional array. Thus, I am able to get value whatever I need from all of the data.

Gathering all data in 1 array make me easy to save the data made by app. Because, what I need to save is only serializing the instance of "save" class.

The way to save data is cleared, so next issue is how can I get value from instance deserialized, and how can the instance be shered by all class.

It is the all of my study today.
This report is too little but it is late for me, so I'll go to bed from now on.
See you.


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.


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.


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.

<AnchorPane fx:id="topAnc"  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ctrl.Controller">
      <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">
          <AnchorPane fx:id="trAnc">
                  <TreeView fx:id="trvFld" />
                  <Label />
      <TabPane fx:id="tabFld" layoutX="140.0" layoutY="25.0" tabClosingPolicy="UNAVAILABLE" />

Allit took was adding menuBr to topAnc.

Today's learned.

//The csv file edit by typing to cell directly.

At tableTest, I tried to directry edit to cell in TableView many times.
Just editting has go right at first trial, but new value after editting does not appear in the TableView.
Finally, I finished that problem by adding new EventHandle and method to edit sheet.csv by getting value and position from my selected cell.
That method is named "editSheet()". It needs three arguments.
First one is integer type, number of row at selected cell, gotten by method getTablePosition().getRow().
The second is integer too, number of column at selected cell.
The third is String type, new value for edit, gotten by method getNewValue().
That EventHandle has this method "editSheet()" and "getSheet()".
These method and EH work to change contents of the sheet.csv and show new contents on the TableView by read csv again, when I edit cell.


//The way to show new tabs

I was worry about I couldn't show new tabs in TabPane because I never found the way to show by web search.
At all, I realized it by myself. And There are the detail of my trial and results.
Firstly, I set one Tab type field. Next, I learned TabPane shows tabs depending on it's special ObservableList. TabPane doesn't know how it create new tab, but just has method to add new tab into it's ObservableList. I am sure that the method is only way to create new Tab.
Make a instance of Tab class. Initialize ObservableList by calling method "getTabs()" in TabPane. Call "add()" with Tab instance as argment, and TabPane should get new value and show tabs not only new tab I created but also older.


On the next step. I wondered I would use many kinds of tab and had to write everytime I need.
But I guessed, to avoid writing same code many times, making the original class extends Tab class is easier for me. So I experimented to make "testExtendsTab" extends Tab class has own method, and set it into OL as argment. I found that TabPane shows "testExtendsTab" titled by its method.


This is all about me today.

See you.