I see that this issue has been reported before, but closed because it wasn’t replicated. I figured before I posted another Issue that I would see if anyone else ran into it. Here is a test sketch:
For me, scroll is always zero, when it should be positive or negative depending on how the wheel is moved. This issue only occurs when using FX2D as the renderer.
For context:
Processing version: 4.3
Operating System and OS version: Windows 10 Home 22H2 19045.3324
I would be surprised if your javafx approach works. Processing has not fully implemented javafx and only a few things work since the authors have left out most of the javafx modules. For example do you have code for a more complex example of using javafx, other than opening a window? It will open a window but in my experience it is useless for javafx components. I use size(1,1,FX2D) just to get the code to run, but the actual javafx window is dictated by the size of the pane as shown below. Note that draw is not used at all. In my opinion, in order to get mouse events to work you will need to use a javafx event handler and not Processing calls.
import processing.javafx.*;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
void setup(){
size(1,1, FX2D);
Stage stage = new Stage();
stage.setTitle("JavaFX Demo");
Pane pane = new Pane();
Text text = new Text(70, 100, "Welcome to JavaFX!" );
text.setUnderline(true);
text.setFont(new Font(25));
pane.getChildren().add(text);
Scene scene = new Scene(pane, 400, 400, Color.ALICEBLUE);
stage.setScene(scene);
stage.show();
}
void draw(){
}
Thanks for the reply, this is very helpful. I can’t run your sketch, it tells me I am missing the javafx package. Where can I find it? I’m guessing it’s different than the one processing provides.
Yeah I figured I might need to handle inputs with just javafx. Do you know any good resources for learning how to work with javafx and do this?
I’m surprised that you are unable to run the demo since it only uses text. I’m a Mac user but do have a Windows 11 system so I will see if I can get something that you can run. In the meantime here are a couple of references so that you can see what has been done in the past. To make a long story short the only way that I know of to use all the javafx modules with Processing 4 is to modify the Processing source code to add the ones that were left out by the authors. A request was made to the authors to add them, but to date this has not been done. However, you could do it yourself by editing the source code (Processing IDE is open source) and re-compiling the editor. I’ve done it but it is somewhat cumbersome and is not easy. You also might try an older version of Processing, eg version 3.x.x since it included more of the modules.
Addendum:
Make sure that there is a ‘javafx’ folder inside of your ‘libraries’ folder in your sketchbook. You can go to the Preferences menuItem in the Processing app to see where that is located on your system. You also need to make sure that it is installed to start with: use Tools/ManageTools/Libraries/JavaFx to see if has a check mark beside it. On Windows it could be installed but just not where it needs to be. You should be able to run the simple demo that I posted if the file is where its expected to be.
Addendum2: For whatever it’s worth, I have the ‘javafx’ folder inside my ‘libraries’ folder in my Processing folder in Windows 11 and it still won’t run. Don’t know why.
Yeah, I checked too and ‘javafx’ is in the libraries folder and installed but it is not working. It handles the first import fine, but everything else doesn’t seem to work
Also needs to be a Modules folder inside the Windows folder with seven jar files inside. Unfortunately I have all of that too but still it doesn’t run.
Addendum: Finally got it to run on Windows 11. Inside the project’s sketchbook folder create a new folder called ‘code’. Inside that folder copy/paste the seven javafx jar files. Let me know if you can’t find them and I’ll post a DropBox link.
I found the following example on StackOverflow and modified it to run in the Processing 4 editor. Please see if you can run it. The mouse wheel may be used to change the size of the dot.
//https://stackoverflow.com/questions/29735651/mouse-scrolling-in-java-fx
import processing.javafx.*;
import javafx.scene.layout.Pane;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.input.ScrollEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
void addMouseScrolling(Node node) {
node.setOnScroll((ScrollEvent event) -> {
// Adjust the zoom factor as per your requirement
double zoomFactor = 1.05;
double deltaY = event.getDeltaY();
if (deltaY < 0) {
zoomFactor = 2.0 - zoomFactor;
}
node.setScaleX(node.getScaleX() * zoomFactor);
node.setScaleY(node.getScaleY() * zoomFactor);
}
);
}
void setup() {
size(1, 1, FX2D);
Stage stage = new Stage();
Pane pane = new Pane();
Scene scene = new Scene(pane, 350, 300);
stage.setTitle("Dots");
stage.setScene(scene);
Circle circle = new Circle(175, 150, 10, Color.BLUE);
addMouseScrolling(circle);
pane.getChildren().add(circle);
stage.show();
}
void draw() {
}