Glowy ellipses using javaFX bloom [MULTIPLE QUESTIONS]

You can get the cause by adding

try {

} catch (InvocationTargetException e) {

This way you can see where the problem lies specifically. Please do this and tell us what you got.

Also, you did declare the canvas variable, but never the surface variable in the Code you posted, which is likely the cause of the problem.

Getting error > The class InvokationTargetException doesn’t exist.

Also how do I declare the surface?

You need to include

import java.lang.reflect.InvocationTargetException;

The import java.lang.reflect.InvokationTargetException cannot be resolved

You declare a variable like this

ClassName variableName; //or
ClassName variableName = new ClassName(); // or for primitives
ClassName variableName = ClassValue; // for Int it‘s a number, for String a String like „Hello“ etc.

Edit : It‘s Invocation, not Invokation. (Autocorrect messed me up)

Error > Unreachable catch block for InvocationTargetException. This exception is never thrown from the try statement body

And I still don’t understand, how should I decalre the canvas

Yeah, that just shows that it‘s from outside the function. In this case it‘s very likely from the not declared surface variable.

How do I declare it, like what should I use?

className varName;
className varName = new className();
className varName = classValue;

Also I have this in my code > Canvas canvas = (Canvas) surface.getNative();

import processing.javafx.PSurfaceFX;
import processing.core.PSurface;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.effect.Bloom;

PSurfaceFX surface;
Canvas canvas;

void setup() {
  size(800, 600);

void draw() {
  fill(255, 100);
rect(0, 0, width, height);

surface = (PSurfaceFX) getSurface();
canvas = (Canvas) surface.getNative();
canvas.setEffect(new Bloom());

Since you are going to set surface inside the Setup function, you can just declare it without a specific value. Same for canvas. And pay attention to the order in which variables are set. In this case, if canvas where to already be declared with a value outside the function, you‘d end up refering to the surface variable before it has a value.

Error > ClassCastException: processing.awt.PSurfaceAWT cannot be cast to processing.javafx.PSurfaceFX

Try changing PSurfaceFX into a normal PSurface. Since you didn‘t define the sketch differently in size() it should be default, and i doubt the default is fx, and more likely to be an AWT if it‘s Java2D… Anyway, FX probably isn‘t needed for the surface, so just change the Class from FX to the normal variant.

Hello! Thank you for your help, but I just realized I said “javaFX” instead of “postFX”.

Oh… you mean postFx the Library by cansik?

yes postFX. idk if cansik made it.

Then read the Code here :

It perfectly shows how Bloom effect is implemented. :sweat_smile:

Just add the 3 lines with fx to your code. Note, the third one is split in 4 lines.


see also

1 Like

Thank you !!!


Late to this party, but I have some JavaFX code inside of P5 JAVA to share if anybody finds this helpful. The only note I wanted to add to this thread is often times I work with FX2D in my setup() call.

FIXLIB can be found here, but there’s really no JavaFX specifics in there.

1 Like