Hi ,
 I experience shaking lines . I have given the code below. The code
creates a splitpane and adds  JInternalFrame to either side of the
splitpane.
The canvas ( an extension of JComponent ) realigns the coordiante system
with that of
conventional X and Y cocordinate system. That is, +ve X is to the right
and  +ve Y is to the top and the origin is in south west corner. The
canvas is added to the rigth-hand JInternalFrame. You can see that the
the line shakes if you either a. you select the left-JInternalFrame or
b.move the separator the splitpane.

I am unable to figure out why this is happening . One clue is that if
you do not align the cocordinate system , no shaking is takes place. In
fact, the AffineTransform with the graphics passed to the canvas keeps
on changing whenever you do either of the above actions.

Since our application entirely deals with world cocordinate system, the
shaking line phenomenon is a severe jolt. Could someone please tell me
why it occurs and , more importantly, a solution.

Thanks.

ganesan

import javax.swing.* ;
import java.awt.* ;
import java.awt.geom.* ;
import java.awt.geom.AffineTransform ;
import common.* ;

public class ShakyLine2 extends JFrame
{
  // canvas to draw
  public class OurCanvas extends JComponent
  {
    public OurCanvas()
    {
      super() ;
    }

    public void paintComponent( Graphics g )
    {
      Graphics2D g2 = ( Graphics2D ) g ;

      // the affine transform keeps on changing
      System.out.println( g2.getTransform() ) ;

      // realign the cocordinate system with conventional
      // x and y cocordiante syatem
      AffineTransform at = new AffineTransform(1.0 , 0.0 , 0.0 , -1.0 ,
                       0.0 , getSize().height ) ;
      g2.setTransform( at ) ;
      g2.drawLine( 0 , 0 , 300 , 300 ) ;
    }
  }

  private JInternalFrame jif1 = new JInternalFrame() ;
  private JInternalFrame jif2 = new JInternalFrame() ;
  private JDesktopPane jdp1 = new JDesktopPane() ;
  private JDesktopPane jdp2 = new JDesktopPane() ;
  JSplitPane jSplitpane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
true,
                                           jdp2, jdp1 ) ;


  private OurCanvas oc = new OurCanvas() ;

  public ShakyLine2()
  {
    super() ;
    initGUIElement() ;
    setSize( new Dimension( 400 , 400 ) );
    setVisible( true ) ;
  }

  private void initGUIElement()
  {
    setContentPane( jSplitpane ) ;
    jdp2.add( jif2  , new Integer( 10 ) ) ;
    jdp1.add( jif1 , new Integer( 10 )) ;
    jif1.setBounds( 0 , 0 , 200 , 200 ) ;
    jif2.setBounds( 0 , 0 , 100 , 100 ) ;

    jif1.getContentPane().add(( oc ) );
    jif1.setOpaque( true ) ;
    jif1.setBackground( Color.white ) ;
  }

  public static void main( String[] args )
  {
    new ShakyLine2() ;
  }
}

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to