JavaFX线程使UI无响应,任何替代方法[线程延迟]
JavaFX线程正在使UI变慢并挂起 这是代码,如果有人能提出原因或替代方案,这将是有益的 这是一个MVC应用程序。当代码点击这个线程时,它工作正常,UI没有挂起,但它没有挂起,然后它就会变成空白和无响应 这是一个线程延迟问题JavaFX线程使UI无响应,任何替代方法[线程延迟],java,multithreading,user-interface,javafx,Java,Multithreading,User Interface,Javafx,JavaFX线程正在使UI变慢并挂起 这是代码,如果有人能提出原因或替代方案,这将是有益的 这是一个MVC应用程序。当代码点击这个线程时,它工作正常,UI没有挂起,但它没有挂起,然后它就会变成空白和无响应 这是一个线程延迟问题 Platform.runLater(new Runnable() { @Override public void run() { DecimalFormat df = new DecimalFormat("#,##0.00");
Platform.runLater(new Runnable() {
@Override
public void run() {
DecimalFormat df = new DecimalFormat("#,##0.00");
setLabel(bidSide, viewResource_.getString(SELL), 95, 121, JFXConstants.jfxWhiteSmoke);
setLabel(askSide, viewResource_.getString(BUY), 145, 121, JFXConstants.jfxWhiteSmoke);
setLabel(bidAmount, df.format(0.0), 0, 122, JFXConstants.jfxGrey);
setLabel(askAmount, df.format(0.0), 146, 122, JFXConstants.jfxGrey);
bidAmount.setPrefWidth(110);
bidAmount.setScaleX(0.87);
bidAmount.setScaleY(0.87);
bidAmount.setAlignment(Pos.CENTER_LEFT);
askAmount.setPrefWidth(110);
askAmount.setScaleX(0.87);
askAmount.setScaleY(0.87);
askAmount.setAlignment(Pos.CENTER_RIGHT);
unlock.setVisible(false);
lock.setVisible(false);
lock.setOpacity(0.7);
root.setStyle(FX_BACKGROUND_COLOR + fxBlackString);
greyPanel = createRectangle(310.0, 135.0, JFXConstants.jfxGrey, 0.0, 5.0);
greyPanel.setOpacity(0.6);
root.getChildren().add(greyPanel);
if (getFastFXController().getModel() != null && getFastFXController().getModel()
.getCurrency_() != null &&
!getFastFXController().getModel().getCurrency_().equals(LNFConstants.EMPTY_STRING)) {
try {
javafx.scene.image.Image image =
new javafx.scene.image.Image(setImagePath(getFastFXController().getModel()
.getCurrency_()));
flagView = new ImageView(image);
} catch (Exception e) {
flagView = new ImageView();
}
flagView.setLayoutX(6.0);
flagView.setLayoutY(11.0);
flagView.setFitWidth(242);
flagView.setFitHeight(108);
root.getChildren().add(flagView);
}
bidRect = new javafx.scene.shape.Rectangle();
offerRect = new javafx.scene.shape.Rectangle();
nearTenorGroup.getChildren().addAll(nearTenorRect,
createJFxLabel(nearLabel, NEAR, 1, 0, JFXConstants.jfxWhite, javafx.scene.text.Font.font(FONT_ARIAL, FontWeight.NORMAL, 12)),
createJFxLabel(tenor_, FastFXView.this.getFastFXController().getModel().getTenor_(), 9, 7, JFXConstants.jfxWhite, javafx.scene.text.Font.font(FONT_ARIAL, FontWeight.EXTRA_BOLD, 14))
);
nearLabel.setOpacity(0.4);
tenor_.setOnMouseClicked(new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent mouseEvent) {
popUpGroups.get(NEAR_TENOR).requestFocus();
popUpGroups.get(NEAR_TENOR).setVisible(true);
popUpGroups.get(NEAR_TENOR).setLayoutX(219);
popUpGroups.get(NEAR_TENOR).setLayoutY(1);
popUpGroups.get(NEAR_TENOR).requestFocus();
tenor_.setTextFill(JFXConstants.jfxGrey);
}
});
tenor_.setOnMouseEntered(new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent mouseEvent) {
tenor_.setOpacity(0.8);
}
});
tenor_.setOnMouseExited(new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent mouseEvent) {
tenor_.setOpacity(1);
}
});
root.getChildren().add(nearTenorGroup);
farTenorGroup.getChildren().addAll(farTenorRect,
createJFxLabel(farLabel, FAR, 1, 0, JFXConstants.jfxWhite, javafx.scene.text.Font.font(FONT_ARIAL, FontWeight.NORMAL, 12)),
createJFxLabel(tenorFar_, FastFXView.this.getFastFXController().getModel().getTenorFar_(), 9, 7, JFXConstants.jfxWhite, javafx.scene.text.Font.font(FONT_ARIAL, FontWeight.EXTRA_BOLD, 14))
);
farLabel.setOpacity(0.4);
tenorFar_.setOnMouseClicked(new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent mouseEvent) {
popUpGroups.get(FAR_TENOR).requestFocus();
popUpGroups.get(FAR_TENOR).setVisible(true);
popUpGroups.get(FAR_TENOR).setLayoutX(219);
popUpGroups.get(FAR_TENOR).setLayoutY(5);
popUpGroups.get(FAR_TENOR).requestFocus();
tenorFar_.setTextFill(JFXConstants.jfxGrey);
}
});
tenorFar_.setOnMouseEntered(new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent mouseEvent) {
tenorFar_.setOpacity(0.8);
}
});
tenorFar_.setOnMouseExited(new EventHandler<javafx.scene.input.MouseEvent>() {
@Override
public void handle(javafx.scene.input.MouseEvent mouseEvent) {
tenorFar_.setOpacity(1);
}
});
root.getChildren().add(farTenorGroup);
nearTenorGroup.setLayoutX(257);
nearTenorGroup.setLayoutY(10);
farTenorGroup.setLayoutX(257);
farTenorGroup.setLayoutY(25);
setItemsForPopup(NEAR_TENOR, getFastFXController().getModel().getTenors_());
setItemsForPopup(FAR_TENOR, getFastFXController().getModel().getTenorsFar_());
mapRectToPane(bidRect, liveBid);
mapRectToPane(offerRect, liveAsk);
bidRect.setFill(JFXConstants.jfxTransparent);
offerRect.setFill(JFXConstants.jfxTransparent);
root.getChildren().addAll(liveBid, liveAsk);
root.getChildren().addAll(flip, toggle, lock, unlock);
root.getChildren().addAll(offerRect, bidRect);
root.getChildren().addAll(bidSide, bidAmount, askSide, askAmount);
mouseEvents();
}
}
Platform.runLater(新的Runnable(){
@凌驾
公开募捐{
DecimalFormat df=新的DecimalFormat(“#,##0.00”);
setLabel(bidSide,viewResource_uu.getString(SELL),95121,JFXConstants.jfxWhiteSmoke);
setLabel(askSide,viewResource_uu2;.getString(BUY),145,121,JFXConstants.jfxWhiteMoke);
setLabel(bidAmount,df.format(0.0),0,122,JFXConstants.jfxGrey);
setLabel(askAmount,df.format(0.0),146,122,JFXConstants.jfxGrey);
bidAmount.setPrefWidth(110);
投标金额.固定标度(0.87);
投标金额(0.87);
bidAmount.setAlignment(位置中心左);
askAmount.setPrefWidth(110);
askAmount.setScaleX(0.87);
askAmount.setScaleY(0.87);
askAmount.setAlignment(位置中心右);
unlock.setVisible(假);
lock.setVisible(false);
锁定不透明度(0.7);
root.setStyle(FX_背景色+fxBlackString);
greyPanel=createRectangle(310.0135.0,JFXConstants.jfxGrey,0.0,5.0);
灰板毛不透明度(0.6);
root.getChildren().add(greyPanel);
if(getFastFXController().getModel()!=null&&getFastFXController().getModel()
.getCurrency_uz()!=null&&
!getFastFXController().getModel().getCurrency_uz().equals(LNFConstants.EMPTY_字符串)){
试一试{
javafx.scene.image.image=
新的javafx.scene.image.image(setImagePath(getFastFXController().getModel())
.getCurrency_uz());
flagView=新图像视图(图像);
}捕获(例外e){
flagView=新的ImageView();
}
flagView.setLayoutX(6.0);
flagView.setLayoutY(11.0);
flagView.setFitWidth(242);
flagView.setFitHeight(108);
root.getChildren().add(flagView);
}
bidRect=newjavafx.scene.shape.Rectangle();
offerRect=newjavafx.scene.shape.Rectangle();
nearTenorGroup.getChildren().addAll(nearTenorRect,
createJFxLabel(nearLabel,NEAR,1,0,JFXConstants.jfxWhite,javafx.scene.text.Font.Font(Font_ARIAL,fontwweight.NORMAL,12)),
createJFxLabel(tenor,FastFXView.this.getFastFXController().getModel().getTenor(),9,7,JFXConstants.jfxWhite,javafx.scene.text.Font.Font(Font_ARIAL,FontWeight.EXTRA_BOLD,14))
);
nearLabel.setOpacity(0.4);
tenor_uu.setOnMouseClicked(新事件处理程序(){
@凌驾
公共无效句柄(javafx.scene.input.MouseEvent MouseEvent){
popUpGroups.get(接近主题).requestFocus();
popUpGroups.get(接近主题).setVisible(true);
popUpGroups.get(接近主题).setLayoutX(219);
popUpGroups.get(接近主题).setLayoutY(1);
popUpGroups.get(接近主题).requestFocus();
期限设置填充(JFXConstants.jfxGrey);
}
});
tenor_uu.setOnMouseEntered(新的EventHandler(){
@凌驾
公共无效句柄(javafx.scene.input.MouseEvent MouseEvent){
不透明度(0.8);
}
});
tenor.setOnMouseExited(新的EventHandler(){
@凌驾
公共无效句柄(javafx.scene.input.MouseEvent MouseEvent){
基调不透明度(1);
}
});
root.getChildren().add(nearTenorGroup);
farTenorGroup.getChildren().addAll(farTenorRect,
createJFxLabel(farLabel,FAR,1,0,JFXConstants.jfxWhite,javafx.scene.text.Font.Font(Font_ARIAL,fontwweight.NORMAL,12)),
createJFxLabel(tenorFar,FastFXView.this.getFastFXController().getModel().getTenorFar(),9,7,JFXConstants.jfxWhite,javafx.scene.text.Font.Font(Font_ARIAL,FontWeight.EXTRA_BOLD,14))
);
farLabel.setOpacity(0.4);
tenorFar_u2;.setOnMouseClicked(新的EventHandler(){
@凌驾
公共无效句柄(javafx.scene.input.MouseEvent MouseEvent){
get(FAR_TENOR).requestFocus();
popUpGroups.get(远音阶).setVisible(真);
popUpGroups.get(FAR_TENOR).setLayoutX(219);
popUpGroups.get(FAR_TENOR).setLayoutY(5);
get(FAR_TENOR).requestFocus();
tenorFar_u2;.setTextFill(JFXConstants.jfxGrey);
}
});
tenorFar_uuz.setOnMouseEntered(新的EventHandler(){
@凌驾
公共无效句柄(javafx.scene.input.MouseEvent MouseEvent){
tenorFar_uu.setOpacity(0.8);
}
});
tenorFar_u2;.setOnMouseExited(新的EventHandler(){
@凌驾
公共无效句柄(javafx.scene.input.MouseEvent MouseEvent){
tenorFar_uu.setOpacity(1);
}
});
root.getChildren().add(组);
nearTenorGroup.setLayoutX(257);
nearTenorGroup.setLayoutY(10);
组setLayoutX(257);
第二组:setLayoutY(25);
setItemsForPopup(接近主题,getFastFXController().getModel().getEnors();
setItemsForPopup(FAR_TENOR,getFastFXController().getModel().getEnorsfar_());
马普瑞克托烷(bidRect,liveBid);
mapRectToPane(提供正确、liveAsk);
setFill(JFXConstants.jfxTransparent);
setFill(JFXConstants.jfxTransparent);
root.getChildren().addAll(liveBid、liveAsk);
root.getChildren().addAll(翻转、切换、锁定、,
Task loadDatesFromDB = new Task<Void>() {
@Override
protected Void call() throws Exception {
List<Anfrage> list = ...something works slow...
Platform.runLater(() -> {
progressImage.setImage(null);
});
return null;
}
};
new Thread(loadDatesFromDB).start();