how to draw horizontal line in java swing?
A:
Just like drawing any other line, except the value for the y
axis doesn't change.
Noel M
2010-08-18 15:50:17
Actually this is only true in euclidean space :)
Romain Hippeau
2010-08-19 01:04:29
+2
A:
Depending on your use case, one of these tutorials should help you:
- The Java Graphics API Tutorial => drawing in a swing component
- The Java Swing Tutorial => using swing components
Here an example class which draws a Black line
public class MyLine extends JPanel()
{
@Override public void paint(Graphics g)
{
//Get the current size of this component
Dimension d = this.getSize();
//draw in black
g.setColor(Color.BLACK);
//draw a centered horizontal line
g.drawLine(0,d.height/2,d.width,d.height/2);
}
}
josefx
2010-08-19 17:04:44