When I add swing components to my applet, they don't show up. Sometimes if I move my mouse around some JButtons pop up(strange). I have a method paint(Graphics g){} and update(Graphics g){}, but even when I remove all the images and painting code, the components still don't appear. Is this something normal that happens with applets, or am I making a mistake?
I also had same problem, here is the solution that helped me:
In your paint(Graphics g) method to paint all containers properly use super.paint(g).
Like:
void paint(Graphics g)
{
super.paint(g);
//code to draw something
}
It's common not in applets, but also in Java program. As far as I know, I meet with many cases like that due to the incompatibility issue. When this thing happens, minimize a window and resize it and all the objects pop up as they should. I'm not sure whether there's a solution to that. I think there should be one. This mostly happens when you have objects overlapping.
EDIT: Information maybe useful: When a window is resized in a regular java program, javax.swing.JComponent.repaint() is called.
Ok, I figured it out. Stupid mistake by me. I was using Applet, not JApplet.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.