CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Posts
    4

    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.

    private void jDisplayButtonActionPerformed(java.awt.event.ActionEvent evt) {
    workFlowDialog = new WorkFlowDialog(this, steps);
    workFlowDialog.setVisible(true);
    }

    I am passing a list of the work flow steps (a step has a list of next steps). The constructor of the display dialog is

    public WorkFlowDialog(JDialog parent,
    ArrayList<ProcessingStep> processingSteps) {
    super(parent, true);
    initComponents();
    constructGraph(processingSteps);
    workFlowPanel.setNodesList(nodesList);
    }

    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?

    Your help will be greatly appreciated,

    Alejandro Barrero

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Can't display my graphics in a JPanel

    Have you checked your X & Y values to make sure they are in the visible area of the panel.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured