File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Drawing a Chart. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing a Chart." Watch "Drawing a Chart." New topic

Drawing a Chart.

Rakesh Jhamb
Ranch Hand

Joined: Jun 18, 2003
Posts: 154

I have a swing application already developed and running. I am not a seasoned swings developer, but understand the basics.

My query
We have XML config file that has information flow configuration. For example if information flows from A - > B -> C.

I want to extend this swing application and draw a chart at runtime by reading this config file that will diagramatically show that information is flowing from A to B to C.

Maybe drawing can be like 3 circles connected with Arrows.

I want to know what all technologies will be required within Swings space which I should look at and what options I have to draw something at runtime using information from the config file. Any 3rd party frameworks if required, please tell that as well.

Thank You
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

You can extend a regular JPanel, override its paintComponent method* and do any custom painting on the supplied Graphics object. It's (almost?) always an instance of Graphics2D, so if you need any methods specific to that class you can cast the argument. Use instanceof to avoid any ClassCastExceptions.

* Please be careful:
1) the first statement inside the overridden method should be super.paintComponent(g)
2) keep the method protected

How To Ask Questions How To Answer Questions
Rakesh Jhamb
Ranch Hand

Joined: Jun 18, 2003
Posts: 154
Thanks for your quick reply. This would mean I would have to write code to draw widgets. For example, the challenge with this approach is:

For example, how do I draw a directed arrow. Is there any inbuilt widget in API to do that.

That is why, I wanted to know some framework or API that can be used in conjunction with Swings to draw beautiful diagrams.

Rakesh Jhamb
Ranch Hand

Joined: Jun 18, 2003
Posts: 154
Request you to please reply to this post. How will I draw directed arrows in Swing.

Darryl Burke

Joined: May 03, 2008
Posts: 5115

Two possible ways:

Search the web for a free or commercial package that provides an API for drawing arrows
Write one yourself.

luck, db
There are no new questions, but there may be new answers.
Rakesh Jhamb
Ranch Hand

Joined: Jun 18, 2003
Posts: 154
If we see tools like eclipse, there are various plugins that draw beautiful class diagrams or dependency diagrams. Is that done using raw code inside the plugin, or there is some standard api / library to do this.

I am not able to find something suitable, hence thought of asking swing experts. If you know one, please let me know.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10828

Arrows and directions usually indicate a graph
Check out JGraph

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rakesh Jhamb
Ranch Hand

Joined: Jun 18, 2003
Posts: 154
Hi Manish,

Thanks for your reply. This is exactly what I am looking for. But this is a commercial version, do you know any free utility with basic arrow and circle figures would suffice for my purpose actually.

I agree. Here's the link:
subject: Drawing a Chart.
It's not a secret anymore!