Ability to add an icon to Cancel Button in TaskProgressView

4 views
Skip to first unread message

Mark Schmieder

unread,
Apr 1, 2023, 12:25:09 AM4/1/23
to ControlsFX
This is my third and final legacy enhancement made years ago to my local clone of TaskProgressView, and less obvious in its solution as the way I did it is non-ideal but was the least invasive.

My clients requested a button icon for the Cancel Button to match how the feature is modeled elsewhere in the application. I expect this would be a common request, for common LAF and for intuitive eye-scanning of an application's windows and status.

As everything is private and in the skin, I had no choice but to edit a copy of taskProgressViewSkin and add the following to the TaskCell constructor after the Cancel Button is created:

// Add a helpful graphic to the Cancel Button for clarity.

try {

// Load the JAR-resident Image file into an Image container.

// NOTE: This image comes from ahaSoft, but is copied here as

// otherwise we'd have to pull in outside infrastructure and

// utilities to have access to this icon's usual location.

final Image cancelImage = new Image( "/org/controlsfx/control/Cancel16.png", //$NON-NLS-1$

false );


// Track the Image's error property, to report any errors.

cancelImage.errorProperty().addListener( ( observable, oldValue, imageError ) -> {

if ( imageError ) {

cancelImage.getException().printStackTrace();

}

} );


final ImageView cancelImageView = new ImageView();

cancelImageView.setImage( cancelImage );

cancelImageView.setSmooth( false );

cancelImageView.setCache( true );

cancelButton.setGraphic( cancelImageView );

}

catch ( final Exception e ) {

e.printStackTrace();

}


.

.

.


Ideally, TaskProgressView would expose a public API method for setting the button icon and forward it to the skin, so if I was to do this as a pull request, I would probably revise my original solution accordingly.

Obviously, my solution is too hard-wired for general consumption, as it chooses a specific icon. I grab most of my icons (that I don't design myself or get from someone I collaborate with) from the free softicons website, making sure they're allowed in commercial apps. It would be better to supply via calls to the public API though.

I have far more important and substantial ControlsFX fixes and enhancements to post than the three for TaskProgressView, but need to get my feet wet first with the easy ones.
Reply all
Reply to author
Forward
0 new messages