Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1008677 // Test HighlightCaret (keeps showing selection of JTextField when not in focus)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (2213L/15K).

!7

p-awt {
  JTextField tf1 = jtextfield();
  JTextField tf2 = jtextfield();
  for (JTextField tf : ll(tf1, tf2))
    tf.setCaret(new HighlightCaret);
  showFrame(vgrid(tf1, tf2));
}

sclass HighlightCaret extends DefaultCaret {
    private static final Highlighter.HighlightPainter unfocusedPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
    private static final Highlighter.HighlightPainter focusedPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
    private static final long serialVersionUID = 1L;
    private boolean isFocused;

    @Override
    protected Highlighter.HighlightPainter getSelectionPainter() {
        setBlinkRate(500); // otherwise is disabled, stopped
        return isFocused ? focusedPainter/*super.getSelectionPainter()*/ : unfocusedPainter;
    }

    @Override
    public void setSelectionVisible(boolean hasFocus) {
        if (hasFocus != isFocused) {
            isFocused = hasFocus;
            super.setSelectionVisible(false);
            super.setSelectionVisible(true);
        }
    }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008677
Snippet name: Test HighlightCaret (keeps showing selection of JTextField when not in focus)
Eternal ID of this version: #1008677/1
Text MD5: f1f4f3be686b71cb03c3584f0ea97500
Transpilation MD5: fcc95fbb5f5c2c7d582cf128385c2aae
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-28 07:03:50
Source code size: 1101 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 470 / 1107
Referenced in: [show references]