FlatLaf
FlatLaf copied to clipboard
AnimatedBorder
This PR adds interface AnimatedBorder (extends javax.swing.border.Border)
that automatically animates painting on component value changes.
This is similar to AnimatedIcon (see PR #222)
The cool thing is that the animation is done in the border and it is not necessary to change anything in the UI delegates. This is not yet used, but intended for future animates (issue #66).
The test application FlatAnimatedBorderTest includes (experimental) animated borders for text fields and a minimal example:

Same as above but using 1000ms duration to better see the animation:

Here is the code for a minimal example:
private class AnimatedMinimalTestBorder
implements AnimatedBorder
{
@Override
public void paintBorderAnimated( Component c, Graphics g, int x, int y, int width, int height, float animatedValue ) {
int lh = UIScale.scale( 2 );
g.setColor( Color.blue );
g.fillRect( x, y + height - lh, Math.round( width * animatedValue ), lh );
}
@Override
public float getValue( Component c ) {
return c.isFocusOwner() ? 1 : 0;
}
@Override
public Insets getBorderInsets( Component c ) {
return UIScale.scale( new Insets( 4, 4, 4, 4 ) );
}
@Override public boolean isBorderOpaque() { return false; }
}
// sample usage
JTextField textField = new JTextField();
textField.setBorder( new AnimatedMinimalTestBorder() );