osx - Java/Swing - Tooltip rectangle -
i'm developing java/swing project, , i'm stuck in customization process.
i've extended jtooltip , overrided paint() method draw own tooltip, can't manage remove background around tooltip.
here's paint() override:
/* (non-javadoc) * @see javax.swing.jcomponent#paint(java.awt.graphics) */ @override public void paint(graphics g) { string text = getcomponent().gettooltiptext(); if (text != null && text.trim().length() > 0) { // set parent not opaque component parent = this.getparent(); if (parent != null) { if (parent instanceof jcomponent) { jcomponent jparent = (jcomponent) parent; if (jparent.isopaque()) { jparent.setopaque(false); } } } // create round rectangle shape round = new roundrectangle2d.float(4, 4, this.getwidth() - 1 - 8, this.getheight() - 1 - 8, 8, 8); // draw background graphics2d g2 = (graphics2d) g.create(); g2.setrenderinghint(renderinghints.key_antialiasing, renderinghints.value_antialias_on); g2.setcolor(getbackground()); g2.fill(round); // draw left triangle point p1 = new point(4, 10); point p2 = new point(4, 20); point p3 = new point(0, 15); int[] xs = {p1.x, p2.x, p3.x}; int[] ys = {p1.y, p2.y, p3.y}; polygon triangle = new polygon(xs, ys, xs.length); g2.fillpolygon(triangle); // draw text int cheight = getcomponent().getheight(); fontmetrics fm = g2.getfontmetrics(); g2.setcolor(getforeground()); if (cheight > getheight()) g2.drawstring(text, 10, (getheight() + fm.getascent()) / 2); else g2.drawstring(text, 10, (cheight + fm.getascent()) / 2); g2.dispose(); } } here's (white) background want remove:

i'm running java 1.7.0_05 under osx.
it may because you're setting parent opaque after calling super.paint. also, have called setopaque on jtooltip ? finally, can in addnotify instead of executing code @ every draw:
public void addnotify() { super.addnotify(); setopaque(false); component parent = this.getparent(); if (parent != null) { if (parent instanceof jcomponent) { jcomponent jparent = (jcomponent) parent; jparent.setopaque(false); } } }
Comments
Post a Comment