Results 1 to 3 of 3
- 02-14-2011, 03:04 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Can't display my graphics in a JPanel
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.
I am passing a list of the work flow steps. The constructor of the display dialog isJava Code:private void jDisplayButtonActionPerformed(java.awt.event.ActionEvent evt) { workFlowDialog = new WorkFlowDialog(this, steps); workFlowDialog.setVisible(true); }
The method constructGraph constructs a list of GraphNode, nodesList; this is what I set in the display pane with "javaworkFlowPanel.setNodesList(nodesList);".Java Code:public WorkFlowDialog(JDialog parent, ArrayList<ProcessingStep> processingSteps) { super(parent, true); initComponents(); constructGraph(processingSteps); workFlowPanel.setNodesList(nodesList); }
The display panel, workFlowPanel, extends JPanel and overrides the method paintComponent.
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.Java Code: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); } }
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?
Your help will be greatly appreciated,
Alejandro barrero
- 02-14-2011, 03:15 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Add some println's to the paint component (or use a debugger) to make sure the values used in your painting method are values which paint where you would expect.
- 02-14-2011, 03:40 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Random box game : unsuccessful Buttons & Graphics listneres and JPanel Placement.
By AcousticBruce in forum New To JavaReplies: 3Last Post: 01-12-2011, 10:43 PM -
Having difficulty adding graphics to a JPanel
By DrKilljoy in forum New To JavaReplies: 20Last Post: 07-20-2010, 08:40 PM -
Jpanel and displaying graphics
By jdsflash in forum New To JavaReplies: 6Last Post: 11-21-2009, 01:14 AM -
Clear Graphics Objects from Jpanel
By DavidG24 in forum AWT / SwingReplies: 2Last Post: 05-20-2009, 09:34 PM -
Newbie need help on JPanel graphics
By junpogi in forum AWT / SwingReplies: 7Last Post: 10-21-2008, 07:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks