hi! i'm trying to customize my program gui (using only java swing) and i'm currently dealing with tooltips. since everything in my program has rounded corners, i wanted the tooltips to have also rounded corners. i tried a lot of things but i can't make it work. the rounded rectangle is drawn perfectly but there are 4 white corners that i can't get rid of (as you can see in the attached picture) even setting the transparency with AlphaComposite.Clear and i'm running out of ideas
this is a custom dummy class i made to test things until i can find the solution:
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
public class CustomTooltip extends JToolTip {
private final Color backgroundColor;
private final Color foregroundColor;
public CustomTooltip(JComponent component, Color backgroundColor, Color foregroundColor) {
super();
setComponent(component);
this.backgroundColor = backgroundColor;
this.foregroundColor = foregroundColor;
setOpaque(false);
setBorder(new EmptyBorder(5, 10, 5, 10));
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// transparency
g2d.setComposite(AlphaComposite.Clear);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setComposite(AlphaComposite.SrcOver);
// rounded rectangle
g2d.setColor(backgroundColor);
g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 15, 15);
// text
g2d.setColor(foregroundColor);
FontMetrics fm = g.getFontMetrics();
int x = 10; // text position
int y = fm.getAscent() + 5;
g2d.drawString(getTipText(), x, y);
g2d.dispose();
}
}
any ideas or recommendations are very helpful! thank you in advance