Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #727

coordinate system and pai

From "Jeff Higgins" <jeff.higgins@THRWHITE.remove-dii-this>
Subject coordinate system and pai
Message-ID <5jVrh.1102$j26.658@newsfe03.lga> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:29 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Hi,
  newbie questions.
When I draw lines in the following
Ruler and RulerCursor paint methods
I draw them both at y=20 but they
do not line up.

When I change Ruler from
extends JPanel to extends Container
RulerCursor does not draw.

Will someone explain what I'm doing wrong?

Thanks,
Jeff Higgins


import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

public class TestLinePosition extends JFrame {

  TestLinePosition() {

    Ruler vRule = new Ruler();
    RulerCursor vCursor = new RulerCursor();
    vRule.add(vCursor);
    MousePad mp = new MousePad();
    JScrollPane sPane = new JScrollPane();
    sPane.setViewportView(mp);
    sPane.setRowHeaderView(vRule);
    sPane.setViewportBorder(new BevelBorder(
                      BevelBorder.LOWERED));
    getContentPane().add(sPane);
  }

  class MousePad extends Component {}

  class Ruler extends JPanel {

    public Ruler() {
      setPreferredSize(new Dimension(20,1000));
    }
    public void paint(Graphics g) {
      super.paint(g);
      g.setColor(Color.black);
      g.drawLine(0, 20, 5, 20);
    }
  }

  public class RulerCursor extends Component {

    public RulerCursor() {
      setPreferredSize(new Dimension(20,1000));
    }
    public void paint(Graphics g) {
      super.paint(g);
      g.setColor(Color.red);
      g.drawLine(5, 20, 10, 20);
    }
  }

  public static void main(String[] args) {
    JFrame frame = new TestLinePosition();
    frame.pack();
    frame.setBounds(100, 100, 200, 200);
    frame.setVisible(true);
  }
}

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

coordinate system and pai "Jeff Higgins" <jeff.higgins@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
  Re: coordinate system and "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000
    Re: coordinate system and "Jeff Higgins" <jeff.higgins@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000

csiph-web