drawling lines in a JPanel

I cannot figure out how to draw a line in a JPanel. The Graphics2D and Line2D classes are not part of JComponent and I cannot figure out how to get a my line from those classes into something JPanel and add as a component.
[229 byte] By [ZodiacKhana] at [2007-10-3 10:56:35]
# 1
You can override the paintComponent() method.
CaptainMorgan08a at 2007-7-15 6:22:30 > top of Java-index,Security,Cryptography...
# 2
I am sorry but I still do not understand. Can you please give a more details?
ZodiacKhana at 2007-7-15 6:22:30 > top of Java-index,Security,Cryptography...
# 3

All JComponents inherit a method:

protected void paintComponent(Graphics g)

Using that Graphics object, which can almost always (with the exception of using DebugGraphics, in my experience and from what I've read, but someone can feel free to contradict me) be safely cast to a Graphics2D object. From either a Graphics or a Graphics2D object you can draw lines.

Another option would be to load line images and display them as the icon of a JLabel using absolute positioning, or implement your own JComponent which draws the lines and then add it to the panel (the Swing tutorial has a nice intro to custom components).

ninthgirla at 2007-7-15 6:22:30 > top of Java-index,Security,Cryptography...