Title: RE: Setting new JPane to a JFrame.

After this line:

m_frame.setContentPane(createPanel(fileChooser.getSelectedFile()));

put:

m_frame.validate();

or

m_frame.pack();

if the size of the frame should/can change.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: maandag 19 januari 2004 9:07
To: [EMAIL PROTECTED]
Subject: Setting new JPane to a JFrame.


This is the most simple code that I found to show this error.

I have JFrame with a complex Content Pane (not this one). I'm trying to
recreate the Content pane for each File but after I set the new Content Pane
there is no Change, But if I try to resize the new Pane alredy apears.

What do I need to set this simple example to work?

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;

public class Main {
    static JFrame m_frame;
    public static void main(String[] args) {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        m_frame = new JFrame("Teste");
        m_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        m_frame.setContentPane(createPanel(null));

        m_frame.pack();
        m_frame.setVisible(true);
    }
   
    static JPanel createPanel(File file) {
        JPanel panel = new JPanel();
        JButton bRecreate = new JButton("Recreate");
        bRecreate.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent arg0) {
                JFileChooser fileChooser = new JFileChooser();
                if (fileChooser.showOpenDialog(m_frame) !=
                    JFileChooser.APPROVE_OPTION)
                        return;
 
m_frame.setContentPane(createPanel(fileChooser.getSelectedFile()));

            }});
        JLabel label = new JLabel();
        if (file != null) {
            label.setText(file.getPath());
        }
        panel.add(label);
        panel.add(bRecreate);
               
        return panel;
    }
}
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
- - - - - - - - DISCLAIMER - - - - - - - -
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.

Reply via email to