|
1 | 1 | /* |
2 | | - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
25 | 25 |
|
26 | 26 | package javax.swing.text; |
27 | 27 |
|
| 28 | +import java.awt.Color; |
28 | 29 | import java.awt.Graphics; |
29 | 30 | import java.awt.HeadlessException; |
30 | 31 | import java.awt.Point; |
@@ -690,7 +691,25 @@ public void paint(Graphics g) { |
690 | 691 | // semantics of damage we can't really get around this. |
691 | 692 | damage(r); |
692 | 693 | } |
693 | | - g.setColor(component.getCaretColor()); |
| 694 | + if (component.isEditable()) { |
| 695 | + g.setColor(component.getCaretColor()); |
| 696 | + } else { |
| 697 | + Color caretColor = component.getCaretColor(); |
| 698 | + if (caretColor == null) { |
| 699 | + caretColor = g.getColor(); |
| 700 | + } |
| 701 | + Color bg = component.getBackground(); |
| 702 | + if (bg == null) { |
| 703 | + g.setColor(caretColor); |
| 704 | + } else { |
| 705 | + int red = (caretColor.getRed() + bg.getRed()) / 2; |
| 706 | + int green = (caretColor.getGreen() + bg.getGreen()) / 2; |
| 707 | + int blue = (caretColor.getBlue() + bg.getBlue()) / 2; |
| 708 | + int alpha = 127; |
| 709 | + Color newCaretColor = new Color(red, green, blue, alpha); |
| 710 | + g.setColor(newCaretColor); |
| 711 | + } |
| 712 | + } |
694 | 713 | int paintWidth = getCaretWidth(r.height); |
695 | 714 | r.x -= paintWidth >> 1; |
696 | 715 | g.fillRect(r.x, r.y, paintWidth, r.height); |
|
0 commit comments