设置Javafx元素在其他类中可见还是不可见

你好?我有一个JavaFX应用程序,可将图像上传到在线服务器。当用户单击上载按钮时,将显示不确定的进度对话框。上传完成后,我想隐藏此进度对话框,但似乎无法正常工作。这是我的代码

通知控制器类

public class NotificationController implements Initializable {

@FXML
public HBox progressHbox;
@FXML
public HBox textHbox;
@FXML
public TextField urlText;
@FXML
private TextField titleText;
@FXML
private ProgressBar progressBar;
@FXML
private AnchorPane rootPane;
Preferences preferences = new Preferences();
@FXML
private Button copyButton;

/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url,ResourceBundle rb) {
    conn = Main.conn;
    progressHbox.setVisible(true);
    textHbox.setVisible(false);
}

@FXML
private void loadOpenUrl(actionEvent event) {
    try {
        Desktop.getDesktop().browse(new URI(imageurl));
        Stage stage = (Stage) rootPane.getScene().getWindow();
        stage.close();
    } catch (IOException | URISyntaxException ex) {
        Logger.getLogger(NotificationController.class.getName()).log(
                Level.SEVERE,null,ex);
    }

}

Connection conn;

@FXML
private void loadCopyUrl(actionEvent event) {

    if (titleText.getText().length() > 0) {
        try {
            String id = imageurl.replaceAll("[^\\d]","");
            ;
            System.out.println("this is id " + id);
            conn.prepareStatement(
                    "UPDATE images set title = '" + titleText.getText()
                            + "' where id = " + id + "").execute();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    Clipboard clipboard = Clipboard.getSystemClipboard();
    ClipboardContent content = new ClipboardContent();
    content.putString(imageurl);
    clipboard.setContent(content);
    Stage stage = (Stage) rootPane.getScene().getWindow();
    stage.close();
}


@FXML
private void loadbuttonText(KeyEvent event) {
    if (titleText.getText().length() > 0) {
        copyButton.setText("Copy/Update");
    } else {
        copyButton.setText("Copy");

    }
}


}

在我的主类中,这就是我最初加载Notificationcontroller的方式

Parent parent = FXMLLoader.load(getclass().getResource(
                    "Notification.fxml"));
            stage = new Stage(StageStyle.DECORATED);
            stage.setTitle("");
            stage.setScene(new Scene(parent));
            // set Stage boundaries to the lower right corner of
            // the visible bounds of the main screen
            stage.setX(primaryScreenBounds.getMinX()
                    + primaryScreenBounds.getWidth() - 422);
            stage.setY(primaryScreenBounds.getMinY()
                    + primaryScreenBounds.getHeight() - 130.0);

            stage.show();

这就是我尝试设置组件可见性的方式:

if (uploadsuccess && !isGoogle) {
                    HBox ph = new HBox();
                    HBox th = new HBox();
                    TextField urls = new TextField();
                    System.out.println("Uploaad suceess testing");
                    NotificationController nc = new NotificationController();
                    ph = nc.progressHbox;
                    th = nc.textHbox;
                    urls = nc.urlText;

                    ph.setVisible(false);
                    th.setVisible(true);
                    urls.setText(imageurl);


                }

我尝试了上述方法,但该方法不起作用,但显示了控制台输出(Uploaad suceess测试)。 有人知道我该怎么做吗?

iCMS 回答:设置Javafx元素在其他类中可见还是不可见

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2249610.html

大家都在问