javaFX元件2-3事

如何偵測TextField資料變動(應適用其他元件)

/*偵測單價的狀況,當變動時啟動偵測機制來檢查金額差距*/
textPrice.textProperty().addListener((observable, oldValue, newValue) -> {
System.out.println(“textfield changed from ” + oldValue + ” to ” + newValue);

Check_Order_Workers_Price();

});

參考資料:https://stackoverflow.com/questions/30160899/value-change-listener-for-javafxs-textfield

偵測TableView的資料列,當條件符合時改變字體顏色。

/*NOTE 字體變色*/
s03.setCellFactory(column -> {
return new TableCell() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);

if(item == null || empty) {
setText(null);
setStyle(“”);
} else {
// Format date.
setText(item);
// Style all dates in March with a different color.
if(item.equals(“銷售”)) {
setTextFill(Color.GREEN);
// setStyle(“-fx-background-color: yellow”);
} else {
setTextFill(Color.RED);
}
}
}
};
});

偵測元件上的鍵盤動作
tf.setOnKeyPressed(new EventHandler<KeyEvent>() {

@Override

public void handle(KeyEvent event) {

if(event.getCode() == KeyCode.A){

// do something

}

}

});

tf.setOnKeyPressed(new EventHandler<KeyEvent>() {

@Override

public void handle(KeyEvent event) {

if(event.getCode() == KeyCode.A){

// do something

}

}

});

參考資料:http://www.javafxchina.net/blog/2015/09/javafx-key-event/

使用Eclipse開發Android相關設定問題!

2018年Android開發平台已經由Google自家的Android Studio為主,其他IDE如Eclipse跟NetBeans很難找到資源,這裡記錄這兩週在建置Eclipse FOR Android時遇到的點點滴滴。

首先是Android SDK開發套件,官方已不容易找到載點。

不容易找到載點

複習如何建立Eclipse for Android開發環境:

https://www.jianshu.com/p/c0c2f8a46cb0

SDK遇到閃退,解決連結:

http://yu0410aries.blogspot.tw/2013/06/sdk-manager.html

https://hk.saowen.com/a/26bf2c7dc7a0c320ea138042c8590ad40d6a4ffd12f115c039eb1afc55e61d5e

https://blog.csdn.net/fl1623863129/article/details/72199816

https://blog.csdn.net/xzlAwin/article/details/45959183

http://blog.xuite.net/free6d1823/blog/76401242-Eclipse+%E8%A3%9D%E5%AE%8C+ADT,+Window+%E5%BA%95%E4%B8%8B%E7%9C%8B%E4%B8%8D%E5%88%B0+Android+SDK+Manager

複習如何安裝SDK:

https://www.androidcentral.com/installing-android-sdk-windows-mac-and-linux-tutorial

http://www.tshopping.com.tw/thread-250607-1-1.html

http://learnexp.tw/%E3%80%90android%E3%80%91%E6%A8%A1%E6%93%AC%E5%99%A8eclipse%E5%AE%89%E8%A3%9D%E6%95%99%E5%AD%B8%E6%96%B0-%E5%BE%9E0%E5%88%B01/

http://www.laird.tw/2016/11/eclipse-android-with-os-x.html

SDK在Win10內的變數設定Path:

https://jingyan.baidu.com/article/15622f2434bc5cfdfcbea51c.html

Android SDK manager結構:

https://blog.csdn.net/u011026779/article/details/53178602

eclipse中graphical layout不顯示手機預覽窗口的問題解決方法(嘗試失敗未解決):

https://read01.com/zh-tw/PMdMzg.html#.WrrwPYhuaUl

https://ifun01.com/V9GPFOY.html

https://blog.csdn.net/myapplication/article/details/47128487

原文網址:https://read01.com/PMdMzg.html

關鍵解決方法:

發現了以元素’d:skin’ 開頭的無效內容。此處不應含有子元素。

http://mydebug.blogspot.tw/2016/01/httpwww.html

https://cnbin.github.io/blog/2016/06/12/da-kai-eclipsebao-cuo-:fa-xian-liao-yi-yuan-su-d-skin-kai-tou-de-wu-xiao-nei-rong-.-ci-chu-bu-ying-han-you-zi-yuan-su/

方法1: 在SDK Manager里删除Android-wear相关的image

方法2: 进入sdk目录下,把

..\android-sdk\system-images\android-22\android-wear\armeabi-v7a\devices.xml和..\android-sdk\system-images\android-22\android-wear\x86\devices.xml文件删除,再把sdk里面..\android-sdk\tools\lib\下的devices.xml拷贝到上述两个文件夹里,重启eclipse即可

adb server is out of date 啟動失敗:

https://blog.csdn.net/liranke/article/details/42524851

解决Android library project cannot be launched

https://blog.csdn.net/welovesunflower/article/details/7990952

解決Unable to build: the file dx.jar was not loaded from the SDK folder

https://blog.csdn.net/qq_32224139/article/details/69525946

https://stackoverflow.com/questions/43009679/unknown-error-unable-to-build-the-file-dx-jar-was-not-loaded-from-the-sdk-fold/43040723

對岸的問題小彙整:

https://blog.csdn.net/androiddevelop/article/details/8130416

https://www.jianshu.com/p/1cc1d2df7f95

Android ADT整合包下載(老舊版本啟動失敗):

http://forum.jeasy.info/viewtopic.php?f=61&t=1521

Eclipse自帶jre檔方法:

http://joerong666.iteye.com/blog/309911

關鍵:

在eclipse.c中,有查找shipped VM的代码,eclipse.exe会先查找有没有自带的JVM,有的话就用它启动:
  /* Find the Directory where the Eclipse program is installed. */
  programDir = getProgramDir();
  …
  
  /* If the user did not specify a VM to be used */
  if (vmName == NULL)
  {
  /* Determine which type of VM should be used. */
  vmName = ((debug needConsole) ? consoleVM : defaultVM);
  
  /* Try to find the VM shipped with eclipse. */
  shippedVM = malloc( (_tcslen( programDir ) + _tcslen( shippedVMDir ) + _tcslen( vmName ) + 10) * sizeof(_TCHAR) );
  _stprintf( shippedVM, _T_ECLIPSE(“%s%s%s”), programDir, shippedVMDir, vmName );
  JavaVM = findCommand( shippedVM );
  
  /* Format a message to indicate the default VM search path. */
  vmSearchPath = malloc( (_tcslen( pathMsg ) + _tcslen( shippedVM ) + _tcslen( vmName ) + 10) * sizeof(_TCHAR) );
  _stprintf( vmSearchPath, pathMsg, shippedVM, vmName );
  free( shippedVM );
  shippedVM = NULL;
  }
  
  eclipseWin.h
  _TCHAR* consoleVM   = _T(“java.exe”);
  _TCHAR* defaultVM   = _T(“javaw.exe”);
  _TCHAR* shippedVMDir = _T(“jre\\bin\\”);
  
  这样就可以通过自带JRE解决客户端库不完全的问题

舊版Java官方載點,需申請Oracle帳密:

http://www.oracle.com/technetwork/java/javase/archive-139210.html

Eclipse 自帶jre啟動運行測試

Eclipse 2016,2017,2018+自留存java 8皆成功啟動並可輸出apk於手機運行

自留存java7,9,10皆無法正常運作(找不到jre檔案)

交叉比對,java 7 x64版jre搭配2018版Eclipse啟動成功!

交叉比對,java 9 x64版jre搭配2018版Eclipse啟動成功!

交叉比對,java 10 x64版jre搭配2018版Eclipse啟動….無法重新安裝(系統玩壞了)….暫時擱置測試,待新版java或有空再測試。

Eclipse 2018+安裝java 10皆成功啟動並可輸出apk於手機運行

目前決定開發環境-沿用2018年版Eclipse+Java8+Android+Gluon(測試中)

Eclipse 2018+系統安裝java啟動運行測試

皆可正常運作,不分java版本

版權聲明:網路搜尋連結,供建立環境快速查找使用,因無個論壇帳號,故留存連結,如原作者有疑義,請mail給我將連結移除mail:gerry.aaa@yahoo.com.tw

JavaFX TableView自訂義排序

package funcion;

import java.util.Comparator;

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.util.Callback;

/**200921-GDK-tableview自訂義排序範例-數字格式化排序*/
public class TableViewCostumerSort extends Application {

private TableView table = new TableView();
private ExtraPerson extraPerson = new ExtraPerson(“Ninja Village”);

private final ObservableList data = FXCollections
.observableArrayList(
new Person(“Jacob”, “1,111”, “jacob.smith@example.com”),
new Person(“Isabella”, “1,123”,
“isabella.johnson@example.com”),
new Person(“Ethan”, “111”,
“ethan.williams@example.com”),
new Person(“Emma”, “222,222”, “emma.jones@example.com”),
new Person(“Michael”, “312”, “michael.brown@example.com”),
extraPerson);

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
stage.setTitle(“Table View Sample”);
stage.setWidth(450);
stage.setHeight(500);

final Label label = new Label(“Address Book”);
label.setFont(new Font(“Arial”, 20));

table.setEditable(true);

TableColumn firstNameCol = new TableColumn(“First Name”);
firstNameCol.setMinWidth(100);
firstNameCol
.setCellValueFactory(new PropertyValueFactory(
“firstName”));

TableColumn moneyCol = new TableColumn(“Money”);
moneyCol.setMinWidth(100);
moneyCol
.setCellValueFactory(new PropertyValueFactory(
“Money”));

TableColumn emailCol = new TableColumn(“Email”);
emailCol.setMinWidth(200);
emailCol.setCellValueFactory(new PropertyValueFactory(
“email”));

/**
* Adding comparator to extraPerson
* 覆寫sort判斷
*/

table.sortPolicyProperty().set(
new Callback<TableView, Boolean>() {

/*自動生成*/
@Override
public Boolean call(TableView param) {
Comparator comparator = new Comparator() {
@Override
public int compare(Person r1, Person r2) {

/*資料形式轉換*/
double r1_d = 0.0;
double r2_d = 0.0;
if (param.getComparator() != null) {
r1_d = Double.parseDouble(r1.getMoney().replaceAll(“,”, “”).trim());
r2_d = Double.parseDouble(r2.getMoney().replaceAll(“,”, “”).trim());
}

/*資料空值try-catch*/
String col_s = “”;
String _sort_s = “”;

try {
col_s = param.getSortOrder().get(0).getText();
_sort_s = param.getSortOrder().get(0).getSortType().toString();
} catch (java.lang.IndexOutOfBoundsException e) {
System.out.println(e);
}

/*設定選取Money欄位時動作*/
if (col_s.equals(“Money”) && !col_s.equals(“”)) {
if (_sort_s.equals(“ASCENDING”)) {
if (r1_d > r2_d) {
/* 0&-1是不排序1是排序 */
return 1;
} else if (r1_d < r2_d) {
/* 0&-1是不排序1是排序 */
return -1;
} else if (param.getComparator() == null) {
/* 0&-1是不排序1是排序 */
return 0;
} else {
/*預設判斷*/
return param.getComparator().compare(r1, r2);
}
} else if (_sort_s.equals("DESCENDING")) {
if (r1_d r2_d) {
/* 0&-1是不排序1是排序 */
return -1;
} else if (param.getComparator() == null) {
/* 0&-1是不排序1是排序 */
return 0;
} else {
/*預設判斷*/
return param.getComparator().compare(r1, r2);
}
} else {
/*預設判斷*/
return param.getComparator().compare(r1, r2);
}
} else {
try {
/*預設判斷*/
return param.getComparator().compare(r1, r2);
} catch (java.lang.NullPointerException e) {
/*排序*/
System.out.println(e);
return 0;
}
}

}
};

/*預設複寫狀態成立*/
FXCollections.sort(table.getItems(), comparator);
return true;
}
});

table.setItems(data);
table.getColumns().addAll(firstNameCol, moneyCol, emailCol);
// table.getColumns().hashCode();
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(label, table);

((Group) scene.getRoot()).getChildren().addAll(vbox);

stage.setScene(scene);
stage.show();
}

public static class Person {

private final SimpleStringProperty firstName;
private final SimpleStringProperty money;
private final SimpleStringProperty email;

private Person(String fName, String money, String email) {
this.firstName = new SimpleStringProperty(fName);
this.money = new SimpleStringProperty(money);
this.email = new SimpleStringProperty(email);
}

public String getFirstName() {
return firstName.get();
}

public void setFirstName(String fName) {
firstName.set(fName);
}

public String getMoney() {
return money.get();
}

public void setMoney(String Money) {
money.set(Money);
}

public String getEmail() {
return email.get();
}

public void setEmail(String Email) {
email.set(Email);
}
}

public static class ExtraPerson extends Person {

private final SimpleStringProperty address;

private ExtraPerson(String address) {
super(“Itachi”, “333”, “leaf@village.ninja”);
this.address = new SimpleStringProperty(address);
}

public String getAddress() {
return address.get();
}

public void setAddress(String address) {
this.address.set(address);
}

}
}