How to update the text of a tooltip in JavaFX while the tooltip is shown?

47 Views Asked by At

I have a series of elements (vehicules) which have a few parameters that I would like to visualize with a tooltip and see how they change. However, I can't find any way to update the tooltip's text while it is being shown.

Currently I am updating the text of the tooltip with the tooltip.onShowing() but this doesn't seem to be the correct approach as it doesn't change the text.

Here you have my current code for it with a parameter example that I would like to update (altitude):

Tooltip tt = new Tooltip(toolTipText);
tt.setOnShowing(event -> {
    tt.setText(toolTipText + "\n" + "Altitude: " + altitude / 1000);
});

Furthermore, the altitude field has been added to this class (vehiculeFX) exclusively to update the tooltip's text and its updated from another class monitor, which controls the state of real vehicules and their representation on a GUI.

Ideally I would like to have a function that can be called from monitor to update the text of the tooltip in vehiculeFX without having to add parameters to this class and that would be called every X milliseconds to update the text.

This is the current loop in the monitor class that takes the information from vehicule and updates vehiculeFX:

@Override
public void run()
{
    int i;
    while (true)
    {
        float vehiculeData[] = new float[10];
        for (i = 0; i < enjambre.numDrones(); i++)
        {
            Vehicule v = vehicules.get(i)
            vehiculeData = v.getVehiculeData();
            vehiculesFX.get(i).updateAltitude(vehiculeData[5]);
        }
    }
}

And I would like to change vehiculesFX.get(i).updateAltitude(vehiculeData[5]); with something like vehiculesFX.get(i).updateTooltip(vehiculeData) to avoid overloading with fields the vehiculeFX class with duplicated information from another class.

0

There are 0 best solutions below