Abrir um arquivo de imagem dentro de um JPanel

0 respostas
Algebra

Estou tentando abrir um arquivo de imagem dentro de um JPanel que está no meu form mas não abre nada, pelo contrario meu form se redimensiona para o tamanho do meu JPanel, oque está acontecendo?

public class F_Principal extends javax.swing.JFrame {

    /** Creates new form F_Principal */
    public F_Principal() {
        initComponents();
    }

    Container container = this.getContentPane();

    @SuppressWarnings("unchecked")
    
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {

        JFileChooser fileChooser = new JFileChooser(new File("C:\Temp"));
        fileChooser.showOpenDialog(this);

        ImageIcon img = new ImageIcon(fileChooser.getSelectedFile().getPath());

        //adiciona a imagem em um label
        JLabel label = new JLabel(img);
        panel1.add(label, BorderLayout.NORTH);

        container.add(panel1, BorderLayout.CENTER);
        this.pack();

    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new F_Principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private java.awt.Panel panel1;
    // End of variables declaration

}
Criado 24 de março de 2010
Respostas 0
Participantes 1