small question. when adding an element to an svg document i am getting a short delay. ie. it takes a second or two for the element to appear after the mouse is clicked. This in it's self is not a major issue but when attempting to draw a free hand line dragging the mouse to quickly causes gaps to be created in the line.
am i doing this correctly? is there some code i am missing? can this be rectified? my code is below and is rather hap hazzard any pointers on cleaning it up would be appreciated... kind regards Danny Browne public void registerListeners(){ // Set the canvas mouse listeners svgCanvas.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent e) { statusLabel.setText("Pressed......"); startPoint = e; } public void mouseReleased(java.awt.event.MouseEvent e) { int x = startPoint.getX(); String sx = new Integer(x).toString(); int y = startPoint.getY(); String sy = new Integer(y).toString(); int w = e.getX(); String sw = new Integer(w).toString(); int h = e.getY(); String sh = new Integer(h).toString(); w = w-x; h = h-y; paint(sx,sy,sw,sh); } }); svgCanvas.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(java.awt.event.MouseEvent e) { int x = startPoint.getX(); String sx = new Integer(x).toString(); int y = startPoint.getY(); String sy = new Integer(y).toString(); int x2 = e.getX(); String sx2 = new Integer(x2).toString(); int y2 = e.getY(); String sy2 = new Integer(y2).toString(); paint(sx,sy,sx2,sy2); startPoint = e; } }); } which calls this method paint method. public void paint (String sx, String sy, String sw, String sh){ toolType = getTool(); if (toolType == 1){ statusLabel.setText("Select Tool Selsected..."); } else if (toolType == 2){ Document doc = svgCanvas.getSVGDocument(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; // get the root element (the svg element) Element svgRoot = doc.getDocumentElement(); // create the rectangle Element line = doc.createElementNS(svgNS, "line"); line.setAttributeNS(null, "x", sx); line.setAttributeNS(null, "y", sy); line.setAttributeNS(null, "y2", sw); line.setAttributeNS(null, "y2", sh); line.setAttributeNS(null, "style", "stroke:black;stroke-width:2"); //attach the rectangle to the svg root element svgRoot.appendChild(line); } else if (toolType == 3){ statusLabel.setText("Paint Tool Selsected..."); } else if (toolType == 4){ Document doc = svgCanvas.getSVGDocument(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; statusLabel.setText("w: " +sw+ " h: " +sh+ " x: " +sx+ " y: " +sy); // get the root element (the svg element) Element svgRoot = doc.getDocumentElement(); // create the rectangle Element line = doc.createElementNS(svgNS, "line"); line.setAttributeNS(null, "x", sx); line.setAttributeNS(null, "y", sy); line.setAttributeNS(null, "y2", sw); line.setAttributeNS(null, "y2", sh); line.setAttributeNS(null, "style", "stroke:black;stroke-width:2"); //attach the rectangle to the svg root element svgRoot.appendChild(line); } else if (toolType == 5){ Document doc = svgCanvas.getSVGDocument(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; // get the root element (the svg element) Element svgRoot = doc.getDocumentElement(); // create the rectangle Element rectangle = doc.createElementNS(svgNS, "rect"); rectangle.setAttributeNS(null, "x", sx); rectangle.setAttributeNS(null, "y", sy); rectangle.setAttributeNS(null, "width", sw); rectangle.setAttributeNS(null, "height", sh); rectangle.setAttributeNS(null, "fill", "black"); //attach the rectangle to the svg root element svgRoot.appendChild(rectangle); } else if (toolType == 6){ Document doc = svgCanvas.getSVGDocument(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; // get the root element (the svg element) Element svgRoot = doc.getDocumentElement(); // create the rectangle Element circle = doc.createElementNS(svgNS, "circle"); circle.setAttributeNS(null, "cx", sx); circle.setAttributeNS(null, "r", "25"); circle.setAttributeNS(null, "cy", sy); circle.setAttributeNS(null, "style", "fill:crimson"); //attach the rectangle to the svg root element svgRoot.appendChild(circle); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]