Skip to content
Advertisement

I am not able to load a graph via JFileChooser and actually display it

So, I have a class that inherits from JFrame with two JSplitPanes and a menu bar. One JSplitPane has a JSplitPane on top and a textarea on the bottom and the other one two JPanels left and right. I want to parse a pnml-file (or more, but I’m just trying to get one working right now) that I chose via JFileChooser. I can choose a file and I tested it by printing the filename and that is working but I can’t manage to actually display the graph in the left JPanel. Maybe someone can help me with that. This is my class:

JavaScript

Before I tried it with the JFileChooser and hardcoded the .pnml-path it worked fine. The constructor looked like this. Now I’m just calling new Fenster_test(“Name of my Frame”); in my main-Method and before I was also doing the parsing in the main-method.

JavaScript

Advertisement

Answer

Since you didn’t provide a minimal, runnable example, I created my own.

Here’s a simple image display GUI.

Image Display GUI

I created a JFrame with a drawing JPanel. The code to create the JFrame is in the run method. The drawing JPanel is created in a separate class. I extend JPanel because I want to override the paintComponent method.

Use this code to create a simple GUI that displays one of your medical images. Once you get that to work, carefully add code to your simple GUI. Test your GUI after each little bit (< 20 lines) of code that you add.

It’s not a good idea to use null layouts and absolute positioning. Swing was designed to be used with layout managers.

Here’s the complete runnable code.

JavaScript
Advertisement