I have a problem displaying in a JPanel figures that I create with java.awt.Graphics. I want to display a work flow tree that I create in a dialog (the display panel is in a different dialog). I have a button in the dialog that creates the tree to open the display dialog, which contains the display panel in a scroll pane.
The method constructGraph constructs a list of GraphNode, nodesList; this is what I set in the display pane with "javaworkFlowPanel.setNodesList(nodesList);".
The display panel, workFlowPanel, extends JPanel and overrides the method paintComponent.
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
graphics.setColor(new Color(153, 255, 255));
for (GraphNode nextGraphNode : nodesList) {
int x = nextGraphNode.i * WorkFlowDialog.SEPARATION + WorkFlowDialog.DIAMETER / 2;
int y = nextGraphNode.j * WorkFlowDialog.SEPARATION + WorkFlowDialog.DIAMETER / 2;
graphics.drawOval(x, y, WorkFlowDialog.DIAMETER, WorkFlowDialog.DIAMETER);
graphics.fillOval(x, y, WorkFlowDialog.DIAMETER, WorkFlowDialog.DIAMETER);
graphics.drawString("X",x, y);
}
}
When the constructor of WorkFlowDialog completes the dialog is displayed and it is using my paintComponent method (I can single step through it). However nothing is displayed.
I am perplexed; I have used code like this in the past and it worked. If the repaint method is executing "graphics.drawOval(x, y, WorkFlowDialog.DIAMETER, WorkFlowDialog.DIAMETER);" why the window doesn't show anything?
Bookmarks