javagwtgwtupload

GWT Java - "getWidget()" is deprecated - what replaces it?


I am loading images using code (please see below) I found through stackoverflow. However, I now notice that the "getWidget()" is deprecated. Rather than wait until this is no longer available I would like to fix this now. What should I use instead of "getWidget()" please?

// Add a finish handler which will load the image once the upload finishes
            existingdefaultUploader.addOnFinishUploadHandler(onReplaceFinishUploaderHandler);
            existingdefaultUploader.getFileInput().getWidget().setStyleName("customButton");
            existingdefaultUploader.getFileInput().getWidget().setSize("100px", "20px");

Regards,

Glyn


Solution

  • You can use .asWidget() instead.

    Sometimes classes comment what method to use instead of the deprecated one.
    In this case there is no comment. However you can look at the source code to see how the class itself implements the deprecated method:

    @Deprecated
    public Widget getWidget() {
      return asWidget();
    }
    

    EDIT: As mentioned in the comments, the Javadoc of the latest version even tells you what to use instead of the deprecated method.