I'm writing a graphical user interface to plot data on a xy-axis. It's written in Java Swing so I have a JFrame
that contains the whole GUI. One of the components of the GUI is a JPanel
that makes up the area where the data is plotted. I use Graphics2D
to do my drawing.
I'm trying to make a command line extension of this program. The idea is that the user can specify the data that they want plotted in a config file. This allows for interesting parameter sweeps that save a lot of time.
The problem occurs when I try to obtain a Graphics
object to draw with. I create the JPanel
that does the drawing, but the Graphics
object is null when I call paintComponent()
.
Also, when you run the program (from command line again), it steals focus from whatever else you're trying to do (if this program is running in the background). Is there anyway to get around that? Do you have to create a JPanel
to do drawing?
Thanks for any help provided!
P.S. When I say that I'm running the program from command line, I mean to say that you are not using the GUI. All of the plotting, etc. is being done without an interface. Also, I'm aware that you can't instantiate a Graphics
object.