I am developing an application that transforms an XML file to a dynamic graph so I made a class that extended JPanel to arrange the node (circularnode.java) and I created a class that extended JPanel to add arrows (arrow.java) but when displaying the arrows, they always come behind nodes. The background of circularnode.java hides them.
How can I display a JPanel over another, or control the order of appearance?
Consider extracting the code for directly drawing of the arrows and nodes out of JPanel. Perhaps you can create an Arrow and a Node class that know how to draw themselves, for instance that has a
public void paint(Graphics g)method.Then you could create an
ArrayList<Arrow>andArrayList<Node>fields for your JPanel class, and draw both in the JPanel’spaintComponent(...)method by iterating through the Lists and calling each item’spaint(...)method passing in the Graphics context obtained from the JVM.Otherwise, if you absolutely need to draw these in separate JPanels, one on top of the other, be sure that the top JPanel is not opaque via
setOpaque(false), so that its background won’t be painted, and you can see through it.For more specific help, consider telling us more about your problem, your current code, and even posting some of your code, preferably in the form of an SSCCE (please see the link that describes this very useful construct).
Welcome to stackoverflow.com by the way!