Mdi

Bom dia pessoal… estou a muito tempo tentando resolver este problema:

Estou desenvolvendo um sistema de cadastro como estudo… tenho varias tela usando - JInternalFrame - e uma tela principal com Jframe… tudo certo até ai… mais agora quero colocar uma figura no jframe e não consigo… vou mostra como estou fazendo:

Uso esta classe para o Jpanel (encontra por aqui mesmo):

public class JImagePanel extends JPanel
{
    private BufferedImage image = null;
    private FillType fillType = FillType.RESIZE;

       public JImagePanel(BufferedImage img)
    {
        setImage(img);
    }

      public JImagePanel(File imgSrc) throws IOException
    {
        this(ImageIO.read(imgSrc));
    }

       public JImagePanel(String fileName) throws IOException
    {
        this(new File(fileName));
    }

       public final void setImage(BufferedImage img)
    {
        if (img == null)
            throw new NullPointerException("Buffered image cannot be null!");

        this.image = img;
        invalidate();
    }

       public void setImage(File img) throws IOException
    {
        setImage(ImageIO.read(img));
    }

      public void setImage(String fileName) throws IOException
    {
        setImage(new File(fileName));
    }

    
    public BufferedImage getImage()
    {
        return image;
    }

    @Override
    protected void paintComponent(Graphics g)
    {
       super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g.create();
        fillType.drawImage(this, g2d, image);        
        g2d.dispose();
    }

       public FillType getFillType()
    {
        return fillType;
    }

        public void setFillType(FillType fillType)
    {
        if (fillType == null)
            throw new IllegalArgumentException("Invalid fill type!");

        this.fillType = fillType;
        invalidate();
    }

    public static enum FillType
    {
       
        RESIZE
        {
            @Override
            public void drawImage(JPanel panel, Graphics2D g2d,
                    BufferedImage image)
            {
                g2d.drawImage(image, 0, 0, panel.getWidth(), panel.getHeight(),
                        null);
            }
        },

       
        CENTER
        {
            @Override
            public void drawImage(JPanel panel, Graphics2D g2d,
                    BufferedImage image)
            {
                int left = (panel.getHeight() - image.getHeight()) / 2;
                int top = (panel.getWidth() - image.getWidth()) / 2;
                g2d.drawImage(image, top, left, null);
            }

        },
       
        SIDE_BY_SIDE
        {
            @Override
            public void drawImage(JPanel panel, Graphics2D g2d,
                    BufferedImage image)
            {
                Paint p = new TexturePaint(image, new Rectangle2D.Float(0, 0,
                        image.getWidth(), image.getHeight()));
                g2d.setPaint(p);
                g2d.fillRect(0, 0, panel.getWidth(), panel.getHeight());
            }
        };

        public abstract void drawImage(JPanel panel, Graphics2D g2d,
                BufferedImage image);
    }
}

[size=18]Para chamar as janelas faço assim:[/size]


public class frmTela extends javax.swing.JFrame {

    private static frmTela t;
    private BufferedImage img;    
    String imagem;

     public frmTela() throws IOException {
        initComponents();
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        jSplitPane1.setLeftComponent(Jpainel);
        }

   JImagePanel Jpainel = new JImagePanel("C:\\SeeducJava\\SeeducJava\\imagens\\log.jpg");;;

   JLabel lb = new JLabel();
    public static frmTela getinstancia() throws IOException{

        if(t == null){
            t = new frmTela();
        }
        return t;
    }

    public static JImagePanel  getPainel() throws IOException{
        return getinstancia().Jpainel;
    }


 private void jmiCargosActionPerformed(java.awt.event.ActionEvent evt) {                                          

        try {
            frmCargo f = new frmCargo();
            f.setTitle("Cadastros de cargos.");
            Jpainel.add(f);
            f.setVisible(true);
        } catch (Exception ex) {
            Logger.getLogger(frmTela.class.getName()).log(Level.SEVERE, null, ex);
        }

    }         

Até que funciona mais quando chamo apenas uma janela… o painel aparece com a figura com a formulario… mais quando chamo mais de uma janela… algumas tenho que abrir dentro de outras… o caldo entorna… os formularios não aparecem apenas com compenentes… fica tudo bagunçado…

Se algum puder me ajudar de já agradeço…

Luís

Onde vc adiciona o JPanel no seu JInternalFrame?

E pq vc está adicionando um form dentro do seu panel na linha 34 do segundo código?

Estou adicionando em um jSplitPane.

Na linha 34 eu adiciono meu formulário - JInternalFrame - a intenção é um MDI - por isso que uso os JInternalFrema dentro de um Jpanel…

Luís

Para fazer MDI você adiciona um JInternalPane num JDesktopPane, não num JPanel. Quem vai dentro do JPanel é o desktoppane.

É verdade… ViniGodoy é porque já tentei de varias maneiras colocar uma imagem no JdesktoPane mais não consequi… olha que não foi por falta de tentativa e de pesquisa… vc teria algum exemplo para mim… tenho este mais não funciona:


public class JImagePanel extends JDesktopPane
{

    private static final long serialVersionUID = 1L;

    Image imagem;

    public JImagePanel (String caminho){
        imagem = Toolkit.getDefaultToolkit().getImage(getClass().getResource(caminho));
    }
    
    public void paintComponente(Graphics g){
        super.paintComponent(g);
        if(imagem != null){
            g.drawImage(imagem, 0, 0, this.getWidth(),this.getHeight(),this);
        }
    }


}

Eu chamo no formulário assim


 JDesktopPane Jpainel = new JImagePanel("C:\\SeeducJava\\SeeducJava\\imagens\\log.jpg");

mais a imagem não aparece… foi o mais perto que consegui…

Desde Já obrigado…

Luís