¿Cómo crear un mapa de calor para aplicaciones de swing?

I'm trying to build a tool that will locate a component on a Swing application (eg a button or text field) and 'highlight it'. i was thinking about using the idea of mapas de calor for highlighting.

Has anyone ever used such a thing and maybe can indicate how they can be generated for this idea because I'm not finding a lot of relevant information relating to this.

Gracias por la ayuda por adelantado :)

preguntado el 08 de noviembre de 11 a las 19:11

2 Respuestas

Well, unless I missed something from your question, this should be pretty easy. One can set the background color of almost all Swing components. For Example, all sub-classes of javax.swing.JComponent tiene un setBackground() método en ellos.

The second step is to actually assign a color. For that, you need to know the min, max and the observed value. If we you were to do a simple heatmap e.g. white to red, then you just need to determine the amount of Red component in an RGB Color specification. This can be done with the formula:

int red = ((value-min)/(max-min))*255;
Color color = new Color(red, 255, 255)

Luego asigna color as the background for your button of text field.

respondido 08 nov., 11:23

This is a good suggestion as well. You can do this instead of drawing an overlay (see my response below) - GETah

thanks a lot for this comment... the formula for the colour was so helpful... thanks a lot - ict1991

My suggestion does not rely on Heatmaps but might suite your needs. Most Swing UI components inherit from JComponent which has : - A getLocation method that returns the location of the component on the parent frame - A getSize method that returns the size of the component You can add a method to your frame that looks up a component given its location on the frame (a simple collision detection algorithm will help)

Once you find that component you can draw a semi transparent overlay of any size you want (a rectangle or any other shape) on that location using 2D Graphics (see ejemplo). This way you can outline any component on your main frame given its location. I hope this helps.

respondido 08 nov., 11:23

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.