- Go to design mode
- Right Click on the panel "panou"
- Click "Costumize code"
- In the dialog select in the first combobox "costum creation"
- add after
= new javax.swing.JPanel()
this, so you see this:
panou = new javax.swing.JPanel(){
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g); // Do the original draw
g.drawLine(10, 10, 60, 60); // Write here your coordinates
}
};
Make sure you import java.awt.Graphics
.
The line that you will see is always one pixel thick. You can make it more "line" by doing the following:
Create this method:
public static final void setAntiAliasing(Graphics g, boolean yesno)
{
Object obj = yesno ? RenderingHints.VALUE_ANTIALIAS_ON
: RenderingHints.VALUE_ANTIALIAS_OFF;
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, obj);
}
And add after super.paintComponent(g);
(in your costum creation) this:
setAntiAlias(g, true);
Edit
What you are doing wrong is: you paint the line once (by creating the frame).
When you paint the line the frame is also invisible. The first draw is happening when the frame becomes visible. The frame will be REpainted, so everything from the previous paint will disapear.
Always you resize the frame, everything will be repainted. So you have to make sure each time the panel is painted, the line also is painted.
Martijn