swing - Java 2d coordinate transformation -


I am trying to plot a graph using the Java 2D graphics library and I thought it was with me Was there. I want to plot in the coordination system, where 0,0 is in the center of the panel on the left side, I used the following code and I was feeling that the result was necessary to me.

  Private Wide Doodro (Graphics G) {Graphics2D g2d = (Graphics2D) g; AffineTransform saveAT = g2d.getTransform (); // Get height height of panel height = getHeight (); // Find between dual panels = ((double) height) /2.0; AffineTransform tform = AffineTransform.getTranslateInstance (0.0, yTrans); g2d.setTransform (tform); // Draw the line for the x-axis G2d.drawLine (0, 0, 100, 0); / / Old Transform G2D. Restore the transformations (CATAT); }   

Plotted the original centered in this window.

The problem shows when I added a menu, it was originally offset in the Y direction, it should be twice as high as the menu's size. Do I need an account for the menu size and other containers that I add to the panel?

  Private Zero Dood (Graphics G) {Graphics2D g2d = (Graphics2D) g.create (); Int height = getHeight (); Double yTrans = ((double) height) / 2.0.0; AffineTransform tform = AffineTransform.getTranslateInstance (0.0, yTrans); g2d.transform (tform); // Draw the line for the x-axis G2d.drawLine (0, 0, 100, 0); }   

works, thanks for your help

You might try out the outline of the view

for the basic center on the left side, > previous> g2d.translate (0, H / 2);

To get an honest, cartesian coordinate, use

  g2d.scale (1, -1);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -