java - JLabel getToolTipText() not returning tooltips that have been set -


so i'm working on find locations of jlabels on screen can use these positions generate data later @ these points depending on type of point is.

to keep track of specific points, have set tooltip of important labels text can add them map<string, rectangle>. rectangle give location on screen, size of label. used generate positioning data points.

the problem right not getting strings ive set, using gettooltiptext() on jlabels.

public map<string, rectangle> positions() {             map<string, rectangle> iopoints = new hashmap<>();     return positions(mainpanel, iopoints); }  // runs through each component starting mainpanel contains // labels have tooltips public map<string, rectangle> positions(container p1, map<string, rectangle> iopoints) {      (component p : p1.getcomponents()) {          if (p instanceof jlabel) {              try {                  if (((jlabel) p).gettooltiptext() != null) {                     // never hit @ all???                     system.out.println("has tooltip:" + ((jlabel) p).gettooltiptext());                     rectangle r = p.getbounds();                     component par = p;                     while (par.getparent() != mainpanel) {                         par = par.getparent();                     }                     r = swingutilities.convertrectangle(par, r, mainpanel);                     //point spot = ((jlabel) p).getlocation();                     ((jlabel) p).settext("x=" + r.getx() + ", y=" + r.gety());                     rectangle oldrect = iopoints.put(((jlabel) p).gettooltiptext(), r);                     if (oldrect != null) {                         system.out.println("replaced " + ((jlabel) p).gettooltiptext()                                 + ".\nold rectangle " + oldrect.tostring()                                 + "\nnew rectangle: " + r.tostring());                     }                     //system.out.println("position: " + spot.tostring() + "\tr: " + r.tostring());                 }             } catch (nullpointerexception | illegalcomponentstateexception e) {                 system.out.println("error " + ((jlabel) p).getname());             }         } else {             if (p instanceof jpanel) {                 return positions((container) p, iopoints);             }         }     }      return iopoints;  } 

example code of set tooltips.

tooltip = new string[]{"comp amps temp " + rack.getname() + " `%sgname` `%compname`"};  (int = 0; < numsg; i++) {     (int j = 0; j < comp[i]; j++) {         label = new jlabel("");         label.settooltiptext(tooltip[0]                 .replace("`%sgname`", rack.getsuctiongroupnameindex(i))                 .replace("`%compname`", rack.getsuctiongroupindex(i).getcompressornameindex(j)));         label.setfont(font);         label.setopaque(true);         label.setborder(border);         label.setbackground(colours.bluelight.getcol());         panel.add(label, c);         c.gridx += 1;     } } 

tooltip showing on jpanel

any ideas why jlabel.gettooltiptext(); wont give me values tool tips i've set.

i suggest create class extends jlabel so:

public class tooltippedjlabelorwhateveryouwanttocallit extends jlabel {     string tooltip = null;     @override     public void settooltiptext(string text) {         tooltip = text;         super.settooltiptext(text);     }     @override     public string gettooltiptext() {         return tooltip;     } } 

there might way tooltip text, simple way.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -