I have a collection of objects descended from JComponent that are displayed on an object desended from JPanel.
Basically these JComponent-based objects are components that can be added and placed arbitrarily and can be dragged about on the panel. The panel is in charge of repainting all the tools/components that have been added to it and its paintComponent looks like this:
//inside the panel class...
public void paintComponent(Graphics g) {
super.paintComponent(g);
....
// draw the components
for (GPComponent i : componentManager.getComponents()) {
i.invalidate();
i.repaint();
}
}
Correspondingly the component object has a paintComponent method that draws up the component's appearance:
//inside the component class...
public void paintComponent(Graphics g) {
super.paintComponent(g);
System.out.println("painting myself!");
//draw appearance
...
}
However this does not work! The components are not drawn. They are there, and can be moved, but they are invisible. That debug string never even appears! The only way to get the components to draw properly is to:
1) use i.paint(g) in the panel (rather than i.repaint()), and
2) change the component class's paintComponent(Graphics g) method to paint(Graphics g )
which it seems is an improper way of doing things because repaint() is delayed, which allows multiple rapidfire requests to me merged, etc. I thought repaint() calls update() which calls paint() which calls paintComponent()?!