Skip to content

Commit

Permalink
Disable double buffering for cellhint popup renderer. Fixes #232
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Feb 25, 2021
1 parent f161b36 commit fe4071d
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.*;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void repaint() {
}

private void enter(final I index, final Rectangle bounds, final Rectangle rendererBounds) {
LOGGER.fine("Showing cell popup at index " + index);
LOGGER.log(popupComponent.isShowing() ? Level.FINER : Level.FINE, "Showing cell popup at index " + index);
if (index != null) {
lastIndex = index;
popupComponent.setPreferredSize(bounds.getSize());
Expand Down Expand Up @@ -334,7 +335,11 @@ private void leave() {
}

private Component getRenderer() {
return cellContainer.getEffectiveCellRendererComponent(lastIndex, cellContainer.isEditingCell(lastIndex));
return cellContainer.getEffectiveCellRendererComponent(lastIndex, isCurrentCellEditing());
}

private boolean isCurrentCellEditing() {
return cellContainer.isEditingCell(lastIndex);
}

private Color getBackground(final Component renderer) {
Expand Down Expand Up @@ -401,14 +406,24 @@ public void paint(final Graphics g) {
if (rendererBounds != null && renderer != null) {
paintBackground(g, renderer);
g.translate(-rendererBounds.x, -rendererBounds.y);

// If the renderer is an editor we need to restore the bounds.
Rectangle bounds = renderer.getBounds();
renderer.setBounds(0, 0, rendererBounds.width, rendererBounds.height);
renderer.doLayout();
renderer.paint(g);
renderer.setBounds(bounds);

boolean doubleBuffered = renderer.isDoubleBuffered();
try {
if (renderer instanceof JComponent) {
((JComponent) renderer).setDoubleBuffered(false);
}
renderer.setBounds(0, 0, rendererBounds.width, rendererBounds.height);
renderer.doLayout();
renderer.paint(g);
} finally {
if (renderer instanceof JComponent) {
((JComponent) renderer).setDoubleBuffered(doubleBuffered);
}
}

renderer.setBounds(bounds);
g.translate(rendererBounds.x, rendererBounds.y);
}
g.setColor(getBorderColor());
Expand Down

0 comments on commit fe4071d

Please sign in to comment.