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

31
LINES

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

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (2381L/16K).

1  
!7
2  
3  
p-substance {
4  
  JTextField tf1 = jtextfield();
5  
  JTextField tf2 = jtextfield();
6  
  for (JTextField tf : ll(tf1, tf2))
7  
    tf.setCaret(new HighlightCaret);
8  
  showFrame(vgrid(tf1, tf2));
9  
}
10  
11  
sclass HighlightCaret extends DefaultCaret {
12  
    private static final Highlighter.HighlightPainter unfocusedPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
13  
    private static final Highlighter.HighlightPainter focusedPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
14  
    private static final long serialVersionUID = 1L;
15  
    private boolean isFocused;
16  
17  
    @Override
18  
    protected Highlighter.HighlightPainter getSelectionPainter() {
19  
        setBlinkRate(500); // otherwise is disabled, stopped
20  
        return isFocused ? focusedPainter/*super.getSelectionPainter()*/ : unfocusedPainter;
21  
    }
22  
23  
    @Override
24  
    public void setSelectionVisible(boolean hasFocus) {
25  
        if (hasFocus != isFocused) {
26  
            isFocused = hasFocus;
27  
            super.setSelectionVisible(false);
28  
            super.setSelectionVisible(true);
29  
        }
30  
    }
31  
}

Author comment

Began life as a copy of #1008677

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: #1008678
Snippet name: Test HighlightCaret (keeps showing selection of JTextField when not in focus) with Substance
Eternal ID of this version: #1008678/1
Text MD5: fcad92b0fa113f06e0103c71024b4bb5
Transpilation MD5: 815ed0bb66f8e95842005c90793d471d
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:07:35
Source code size: 1107 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 414 / 855
Referenced in: [show references]