IJPL-197361 Multi-selection is not repainted while focus changing

GitOrigin-RevId: 2f2ec413f1e34644a5c43d86b0309d670f2adf1b
This commit is contained in:
Pavel Porvatov
2025-07-16 17:38:11 +00:00
committed by intellij-monorepo-bot
parent 138020a17f
commit b4967bd2ed
2 changed files with 29 additions and 1 deletions
@@ -17,6 +17,8 @@ import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicListUI;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import static com.intellij.openapi.util.SystemInfo.isMac;
import static com.intellij.ui.paint.RectanglePainter.DRAW;
@@ -223,6 +225,32 @@ public final class WideSelectionListUI extends BasicListUI {
}
}
@Override
protected FocusListener createFocusListener() {
var superFocusListener = super.createFocusListener();
// Support selected items background while changing focus
return new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
if (list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) {
superFocusListener.focusGained(e);
} else {
list.repaint();
}
}
@Override
public void focusLost(FocusEvent e) {
if (list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) {
superFocusListener.focusLost(e);
} else {
list.repaint();
}
}
};
}
/** @noinspection MethodOverridesStaticMethodOfSuperclass, unused */
public static ComponentUI createUI(JComponent list) {
return new WideSelectionListUI();
@@ -10,7 +10,7 @@ import javax.swing.JComponent
internal class ThreeStateCheckBoxPanel : UISandboxPanel {
override val title: String = "ThreeStateCheckBoxPanel"
override val title: String = "ThreeStateCheckBox"
override fun createContent(disposable: Disposable): JComponent {
return panel {