Mercurial Hosting > luan
changeset 1899:ef0438da68ae
prevent FlatLaf from screwing up the cursor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 14 Apr 2025 15:58:18 -0600 |
parents | 49e2103ebf6a |
children | aa24812aaf98 |
files | src/luan/modules/swing/TextAreaLuan.java |
diffstat | 1 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/swing/TextAreaLuan.java Mon Apr 14 14:20:45 2025 -0600 +++ b/src/luan/modules/swing/TextAreaLuan.java Mon Apr 14 15:58:18 2025 -0600 @@ -3,8 +3,13 @@ import java.awt.Rectangle; import java.awt.Graphics; import java.awt.Color; +import java.awt.event.FocusListener; +import java.awt.event.FocusEvent; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; import javax.swing.JTextArea; import javax.swing.UIManager; +import javax.swing.Timer; import javax.swing.text.DefaultCaret; import javax.swing.text.BadLocationException; import goodjava.logging.Logger; @@ -15,8 +20,21 @@ private static final Logger logger = LoggerFactory.getLogger(TextAreaLuan.class); private static final DefaultCaret flatLafCaret = new DefaultCaret() { - @Override public void setSelectionVisible(boolean visible) { - super.setSelectionVisible(true); + private final Timer blinkTimer = new javax.swing.Timer(500, new ActionListener() { + @Override public void actionPerformed(ActionEvent evt) { + setVisible(!isVisible()); + } + }); + + @Override public void focusGained(FocusEvent e) { + super.focusGained(e); + blinkTimer.start(); + } + + @Override public void focusLost(FocusEvent e) { + // Don't call super — we want to keep caret visible + blinkTimer.stop(); + setVisible(true); } };