Show Graphics under Swing components (URGENT)
URGENT !!!
I have been a program which creates and dispays some graphics. I have used a JInternalFrame. Inside of this, I have put a JPanel into a JScrollPane. Finally, I have put into the JPanel some JPanels which are the graphics. I have been those ghaphics overriden the paint(Graphics g) method in the last JPanels.
The problem are that when I run the program and generate the graphics with the appropriate data I only see a JInternalFrame with the JPanel that I put into the JScrollBar but the JScrollBar and the JPanels of the graphics don't are displayed. Then, if I maximize and minimize the JInternalFrame, the JPanels with the graphics appear but the JScrollPane don't have effect (the scrollbars don't work). But if I maximize and minimize the JInternalFrame again, at the end, all are shown (scrollbars and graphics). Why it don't work at the beginning?
I have tried with validate(), repaint(), setVisible(true) even revalidate() methods of the JInternalFrame, JPanels and JScrollBar and that to be good for nothig. Also I capture the ComponentEvent of the Panel inside of the JScrollBar and I repaint all his components (the graphics) but it is useless. Now, I don't know that I can to do, I am desperate.
Please, help me !!!
Here I show you the structure of that part of the program:
class VentanaInterna extends JInternalFrame
{
...
public VentanaInterna(String nombre)
{
super(nombre,
true, // "resizable"
true, // "closable"
true, // "maximizable"
true);// "iconifiable"
setVisible(true);
setSize(300,300);
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
...
}
public void agregarComponente(Component nc)
{
Container cv = new Container();
cv = getContentPane();
cv.add(nc);
setContentPane(cv);
cv.validate();
}
...
}
class Pizarra
{
private JPanel panel;
private FlowLayout fl_panel;
private JScrollPane jsp;
private VentanaInterna v_graficas;
Pizarra()
{
panel = new JPanel();
panel.setBackground(Color.white);
fl_panel = new FlowLayout();
fl_panel.setHgap(0);
panel.setLayout(fl_panel);
jsp = new JScrollPane(panel);
v_graficas =
Engine.mainWindow.nuevaVentana("FBD - Grficas",
Color.white);
v_graficas.agregarComponente(jsp);
panel.addComponentListener(new CLRepaint());
}
public void agregarGrafica(Grafica g)
{
panel.add(g);
panel.validate();
jsp.validate();
}
class CLRepaint implements ComponentListener
{
public void componentHidden(ComponentEvent e)
{
Component[] c = panel.getComponents();
for (int i = 0; i < panel.getComponentCount(); i++)
c.repaint();
}
public void componentMoved(ComponentEvent e)
{
...
}
public void componentResized(ComponentEvent e)
{
...
}
public void componentShown(ComponentEvent e)
{
...
}
}
}
class Grafica extends JPanel
{
...
repaint(Graphics g)
{
...
}
}
Thank you very very much.
Felipe

