Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HiDPI: fix incomplete component repainting at 125% or 175% scaling on Windows #864

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ FlatLaf Change Log
- Theme Editor: Fixed occasional empty window on startup on macOS.
- FlatLaf window decorations: Fixed black line sometimes painted on top of
(native) window border on Windows 11. (issue #852)
- HiDPI: Fixed incomplete component paintings at 125% or 175% scaling on Windows
where sometimes a 1px wide area at the right or bottom component edge is not
repainted. E.g. ScrollPane focus indicator border. (issues #860 and #582)

#### Incompatibilities

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.geom.RoundRectangle2D;
import java.beans.PropertyChangeEvent;
import java.util.Map;
Expand Down Expand Up @@ -61,6 +62,7 @@
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.UIScale;

Expand Down Expand Up @@ -312,11 +314,11 @@ protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {

case BUTTON_TYPE:
b.revalidate();
b.repaint();
HiDPIUtils.repaint( b );
break;

case OUTLINE:
b.repaint();
HiDPIUtils.repaint( b );
break;

case STYLE:
Expand All @@ -328,7 +330,7 @@ protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {
} else
installStyle( b );
b.revalidate();
b.repaint();
HiDPIUtils.repaint( b );
break;
}
}
Expand Down Expand Up @@ -915,7 +917,7 @@ public void propertyChange( PropertyChangeEvent e ) {

@Override
public void stateChanged( ChangeEvent e ) {
super.stateChanged( e );
HiDPIUtils.repaint( b );

// if button is in toolbar, repaint button groups
AbstractButton b = (AbstractButton) e.getSource();
Expand All @@ -927,5 +929,17 @@ public void stateChanged( ChangeEvent e ) {
((FlatToolBarUI)ui).repaintButtonGroup( b );
}
}

@Override
public void focusGained( FocusEvent e ) {
super.focusGained( e );
HiDPIUtils.repaint( b );
}

@Override
public void focusLost( FocusEvent e ) {
super.focusLost( e );
HiDPIUtils.repaint( b );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.SystemInfo;

Expand Down Expand Up @@ -220,7 +221,7 @@ public void mouseReleased( MouseEvent e ) {

private void repaintArrowButton() {
if( arrowButton != null && !comboBox.isEditable() )
arrowButton.repaint();
HiDPIUtils.repaint( arrowButton );
}
};
comboBox.addMouseListener( hoverListener );
Expand Down Expand Up @@ -351,15 +352,15 @@ protected FocusListener createFocusListener() {
@Override
public void focusGained( FocusEvent e ) {
super.focusGained( e );
if( comboBox != null && comboBox.isEditable() )
comboBox.repaint();
if( comboBox != null )
HiDPIUtils.repaint( comboBox );
}

@Override
public void focusLost( FocusEvent e ) {
super.focusLost( e );
if( comboBox != null && comboBox.isEditable() )
comboBox.repaint();
if( comboBox != null )
HiDPIUtils.repaint( comboBox );
}
};
}
Expand All @@ -386,12 +387,12 @@ protected PropertyChangeListener createPropertyChangeListener() {
switch( propertyName ) {
case PLACEHOLDER_TEXT:
if( editor != null )
editor.repaint();
HiDPIUtils.repaint( editor );
break;

case COMPONENT_ROUND_RECT:
case OUTLINE:
comboBox.repaint();
HiDPIUtils.repaint( comboBox );
break;

case MINIMUM_WIDTH:
Expand All @@ -402,7 +403,7 @@ protected PropertyChangeListener createPropertyChangeListener() {
case STYLE_CLASS:
installStyle();
comboBox.revalidate();
comboBox.repaint();
HiDPIUtils.repaint( comboBox );
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void propertyChange( JTextComponent c, PropertyChangeEvent e, Runnable in
case FlatClientProperties.STYLE_CLASS:
installStyle.run();
c.revalidate();
c.repaint();
HiDPIUtils.repaint( c );
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void propertyChange( PropertyChangeEvent e ) {
} else
installStyle( label );
label.revalidate();
label.repaint();
HiDPIUtils.repaint( label );
}

super.propertyChange( e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.Graphics2DProxy;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.UIScale;

Expand Down Expand Up @@ -182,7 +183,7 @@ protected PropertyChangeListener createPropertyChangeListener() {
case FlatClientProperties.STYLE_CLASS:
installStyle();
list.revalidate();
list.repaint();
HiDPIUtils.repaint( list );
break;
}
};
Expand All @@ -205,7 +206,7 @@ protected ListSelectionListener createListSelectionListener() {
Rectangle r = getCellBounds( list, firstIndex, lastIndex );
if( r != null ) {
int arc = (int) Math.ceil( UIScale.scale( selectionArc / 2f ) );
list.repaint( r.x - arc, r.y - arc, r.width + (arc * 2), r.height + (arc * 2) );
HiDPIUtils.repaint( list, r.x - arc, r.y - arc, r.width + (arc * 2), r.height + (arc * 2) );
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;

/**
Expand Down Expand Up @@ -167,7 +168,7 @@ private void rollover( MouseEvent e, boolean rollover ) {
JMenu menu = (JMenu) e.getSource();
if( menu.isTopLevelMenu() && menu.isRolloverEnabled() ) {
menu.getModel().setRollover( rollover );
menu.repaint();
HiDPIUtils.repaint( menu );
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.UIScale;

Expand Down Expand Up @@ -111,7 +112,7 @@ public void propertyChange( PropertyChangeEvent e ) {
} else
installStyle( c );
c.revalidate();
c.repaint();
HiDPIUtils.repaint( c );
break;

case FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.icons.FlatCapsLockIcon;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.UIScale;

/**
Expand Down Expand Up @@ -163,7 +164,7 @@ public void keyReleased( KeyEvent e ) {
}
private void repaint( KeyEvent e ) {
if( e.getKeyCode() == KeyEvent.VK_CAPS_LOCK ) {
e.getComponent().repaint();
HiDPIUtils.repaint( e.getComponent() );
scrollCaretToVisible();
}
}
Expand Down Expand Up @@ -326,7 +327,7 @@ protected void updateRevealButton() {
if( visible != revealButton.isVisible() ) {
revealButton.setVisible( visible );
c.revalidate();
c.repaint();
HiDPIUtils.repaint( c );

if( !visible ) {
revealButton.setSelected( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ protected void installListeners() {
case PROGRESS_BAR_LARGE_HEIGHT:
case PROGRESS_BAR_SQUARE:
progressBar.revalidate();
progressBar.repaint();
HiDPIUtils.repaint( progressBar );
break;

case STYLE:
case STYLE_CLASS:
installStyle();
progressBar.revalidate();
progressBar.repaint();
HiDPIUtils.repaint( progressBar );
break;
}
};
Expand Down Expand Up @@ -294,6 +294,6 @@ protected void setAnimationIndex( int newValue ) {
// Only solution is to repaint whole progress bar.
double systemScaleFactor = UIScale.getSystemScaleFactor( progressBar.getGraphicsConfiguration() );
if( (int) systemScaleFactor != systemScaleFactor )
progressBar.repaint();
HiDPIUtils.repaint( progressBar );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.UIScale;

Expand Down Expand Up @@ -173,7 +174,7 @@ protected void propertyChange( AbstractButton b, PropertyChangeEvent e ) {
} else
installStyle( b );
b.revalidate();
b.repaint();
HiDPIUtils.repaint( b );
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableField;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableLookupProvider;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
Expand Down Expand Up @@ -212,14 +213,14 @@ protected PropertyChangeListener createPropertyChangeListener() {
switch( e.getPropertyName() ) {
case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS:
scrollbar.revalidate();
scrollbar.repaint();
HiDPIUtils.repaint( scrollbar );
break;

case FlatClientProperties.STYLE:
case FlatClientProperties.STYLE_CLASS:
installStyle();
scrollbar.revalidate();
scrollbar.repaint();
HiDPIUtils.repaint( scrollbar );
break;

case "componentOrientation":
Expand Down Expand Up @@ -492,7 +493,7 @@ private void update( int x, int y ) {

private void repaint() {
if( scrollbar.isEnabled() )
scrollbar.repaint();
HiDPIUtils.repaint( scrollbar );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.UIScale;

Expand Down Expand Up @@ -297,11 +298,11 @@ protected PropertyChangeListener createPropertyChangeListener() {
JScrollBar hsb = scrollpane.getHorizontalScrollBar();
if( vsb != null ) {
vsb.revalidate();
vsb.repaint();
HiDPIUtils.repaint( vsb );
}
if( hsb != null ) {
hsb.revalidate();
hsb.repaint();
HiDPIUtils.repaint( hsb );
}
break;

Expand All @@ -321,14 +322,14 @@ protected PropertyChangeListener createPropertyChangeListener() {
break;

case FlatClientProperties.OUTLINE:
scrollpane.repaint();
HiDPIUtils.repaint( scrollpane );
break;

case FlatClientProperties.STYLE:
case FlatClientProperties.STYLE_CLASS:
installStyle();
scrollpane.revalidate();
scrollpane.repaint();
HiDPIUtils.repaint( scrollpane );
break;

case "border":
Expand All @@ -339,7 +340,7 @@ protected PropertyChangeListener createPropertyChangeListener() {
borderShared = null;
installStyle();
scrollpane.revalidate();
scrollpane.repaint();
HiDPIUtils.repaint( scrollpane );
}
break;
}
Expand Down Expand Up @@ -538,14 +539,14 @@ public void componentRemoved( ContainerEvent e ) {
public void focusGained( FocusEvent e ) {
// necessary to update focus border
if( scrollpane.getBorder() instanceof FlatBorder )
scrollpane.repaint();
HiDPIUtils.repaint( scrollpane );
}

@Override
public void focusLost( FocusEvent e ) {
// necessary to update focus border
if( scrollpane.getBorder() instanceof FlatBorder )
scrollpane.repaint();
HiDPIUtils.repaint( scrollpane );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.LoggingFacade;

/**
Expand Down Expand Up @@ -134,7 +135,7 @@ public void propertyChange( PropertyChangeEvent e ) {
} else
installStyle( s );
s.revalidate();
s.repaint();
HiDPIUtils.repaint( s );
break;
}
}
Expand Down
Loading