按下按钮时,进度指示灯冻结。JavaFX
我正在使用设置为-1.0的指示器进度来显示运行按下按钮时,进度指示灯冻结。JavaFX,java,javafx,progress-indicator,Java,Javafx,Progress Indicator,我正在使用设置为-1.0的指示器进度来显示运行loginprocess时的一些加载。 但是,当我按下Enter按钮并用登录过程启动executor时,即使我使用Plataform.runLater设置可见的进度指示器,我的界面仍保持冻结状态 我的按钮事件: public void initManager(final LoginManager loginManager) { btnEntrar.setOnAction(new EventHandler<ActionEvent>(
loginprocess
时的一些加载。
但是,当我按下Enter按钮并用登录过程启动executor时,即使我使用Plataform.runLater
设置可见的进度指示器,我的界面仍保持冻结状态
我的按钮事件:
public void initManager(final LoginManager loginManager) {
btnEntrar.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String email = loginTxtField.getText().trim();
String token = tokenTxtField.getText().trim();
if (email.equals("")) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", "Digite o e-mail");
}
});
return;
}
try {
Future future = loginProcess(email, token);
showLoginLoading(future);
future.get();
if (!loginGatewayFailed && !loginTargetAppFailed) {
Login loginTargetApp = new Login(email, null, null);
loginManager.autheticated(loginTargetApp, loginGateway, gateway, file);
} else {
if (loginTargetAppFailed) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", loginTargetAppFailedCause);
}
});
} else {
if (loginGatewayFailed) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", loginGatewayFailedCause);
}
});
}
}
}
} catch (final Exception ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, ex.getMessage());
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", ex.getMessage());
}
});
}
}
});
}
问题在于线程管理。我试图在主FX视图运行的同一线程中执行登录指令。
我是通过平台计算出来的;如果调用线程是JavaFX应用程序线程,则返回true
为了解决我的问题,我只需要创建一个新线程来运行我的所有登录说明,如下面的示例所示:
public void initManager(final LoginManager loginManager) {
btnEntrar.setOnAction(new EventHandler<ActionEvent>() {
boolean mainThread = Platform.isFxApplicationThread();
System.out.println("This is the main Thread: " + mainThread);
Platform.runLater(new Runnable() {
@Override
public void run() {
progressInd.setVisible(true);
}
});
new Thread() {
public void run() {
boolean mainThread = Platform.isFxApplicationThread();
System.out.println("This is the main Thread: " + mainThread);
String email = loginTxtField.getText().trim();
String token = tokenTxtField.getText().trim();
if (email.equals("")) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", "Digite o e-mail");
}
});
return;
}
try {
Future future = loginProcess(email, token);
// showLoginLoading(future);
future.get();
if (!loginGatewayFailed && !loginTargetAppFailed) {
Login loginTargetApp = new Login(email, null, null);
loginManager.autheticated(loginTargetApp, loginGateway, gateway, file);
} else {
if (loginTargetAppFailed) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", loginTargetAppFailedCause);
}
});
} else {
if (loginGatewayFailed) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", loginGatewayFailedCause);
}
});
}
}
}
} catch (final Exception ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, ex.getMessage());
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", ex.getMessage());
}
});
}
}
}.start();
});
}
public void initManager(最终登录管理器登录管理器){
setOnAction(新的EventHandler(){
布尔主线程=Platform.isFxApplicationThread();
System.out.println(“这是主线程:“+mainThread”);
Platform.runLater(新的Runnable(){
@凌驾
公开募捐{
progressInd.setVisible(true);
}
});
新线程(){
公开募捐{
布尔主线程=Platform.isFxApplicationThread();
System.out.println(“这是主线程:“+mainThread”);
字符串email=loginTxtField.getText().trim();
String token=tokenTxtField.getText().trim();
if(email.equals(“”){
Platform.runLater(新的Runnable(){
公开募捐{
对话。电子邮件(“Erro”、“Digite o e-mail”);
}
});
返回;
}
试一试{
未来=登录过程(电子邮件、令牌);
//ShowLoginLoad(未来);
future.get();
如果(!loginGatewayFailed&!loginTargetAppFailed){
Login loginTargetApp=新登录(电子邮件,空,空);
已授权(loginTargetApp、loginGateway、网关、文件);
}否则{
如果(loginTargetAppFailed){
Platform.runLater(新的Runnable(){
公开募捐{
对话框。错误(“错误”,loginTargetAppFailedCause);
}
});
}否则{
如果(登录失败){
Platform.runLater(新的Runnable(){
公开募捐{
对话框。淋浴错误(“错误”,loginGatewayFailedCause);
}
});
}
}
}
}捕获(最终异常){
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE,例如getMessage());
Platform.runLater(新的Runnable(){
公开募捐{
Dialog.bathror(“Erro”,例如getMessage());
}
});
}
}
}.start();
});
}
private void showLoginLoading(Future future) {
while (!future.isDone()) {
Platform.runLater(new Runnable() {
@Override
public void run() {
progressInd.setVisible(true);
// progressInd.setProgress(-1.0);
}
});
}
}
public void initManager(final LoginManager loginManager) {
btnEntrar.setOnAction(new EventHandler<ActionEvent>() {
boolean mainThread = Platform.isFxApplicationThread();
System.out.println("This is the main Thread: " + mainThread);
Platform.runLater(new Runnable() {
@Override
public void run() {
progressInd.setVisible(true);
}
});
new Thread() {
public void run() {
boolean mainThread = Platform.isFxApplicationThread();
System.out.println("This is the main Thread: " + mainThread);
String email = loginTxtField.getText().trim();
String token = tokenTxtField.getText().trim();
if (email.equals("")) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", "Digite o e-mail");
}
});
return;
}
try {
Future future = loginProcess(email, token);
// showLoginLoading(future);
future.get();
if (!loginGatewayFailed && !loginTargetAppFailed) {
Login loginTargetApp = new Login(email, null, null);
loginManager.autheticated(loginTargetApp, loginGateway, gateway, file);
} else {
if (loginTargetAppFailed) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", loginTargetAppFailedCause);
}
});
} else {
if (loginGatewayFailed) {
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", loginGatewayFailedCause);
}
});
}
}
}
} catch (final Exception ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, ex.getMessage());
Platform.runLater(new Runnable() {
public void run() {
Dialog.showError("Erro", ex.getMessage());
}
});
}
}
}.start();
});
}