Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Second Layout..

Recommended Posts

I am using a frame a triple times, I mean, i want to use the same JFrame to display 3 different setup's of components in a sequencial way. First i as for to select drives, second i display a progressreport, last, user select a certificatedirectory. I am using getContentPane().removeAll() and then i add the new components but this doesn't show. The frame reamins blank after the first removeAll(). Is there some trick.??? Code follows...



class ScanForCertificateStore extends JFrame {  FindCertificates fc;  ScanForCertificateStore sfcs=this;  DefaultListModel lmRoot = new DefaultListModel();  JList lbRoot = new JList(lmRoot);  JScrollPane spRoot = new JScrollPane(lbRoot);  JButton bStartScan = new JButton("Start Scan of Selected ");  File[] Roots;  public ScanForCertificateStore (FindCertificates fc) {    this.fc = fc;    final Container p = getContentPane();    setSize(200,200);    setLocation(100,100);    p.setLayout(new BorderLayout());    p.add(spRoot,BorderLayout.CENTER);    File f = new File("\\");    Roots = f.listRoots();    for(int i=0;i<Roots.length;i++){      lmRoot.addElement(Roots[i].getAbsolutePath());    }    p.add(bStartScan,BorderLayout.SOUTH);    bStartScan.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        // dfeine new layout        JPanel aPanel = new JPanel(new BorderLayout()),            bPanel = new JPanel(new BorderLayout());        final DefaultListModel lmFound = new DefaultListModel();        JList lbFound = new JList(lmFound);        JButton bAbort = new JButton("Abort Scanning Computer"),            bSelect = new JButton("Select a Certificate Store");        final JTextArea taReport = new JTextArea("");        JScrollPane spFound = new JScrollPane(lbFound),            spReport = new JScrollPane(taReport);        aPanel.add(spReport,BorderLayout.CENTER);        aPanel.add(bAbort,BorderLayout.SOUTH);        bPanel.add(spFound,BorderLayout.CENTER);        bPanel.add(bSelect,BorderLayout.SOUTH);                p.removeAll();   // fisrt removeAll() (second isn't there jet..        p.add(aPanel,BorderLayout.NORTH); // These componets don't show up on tyhe frame...        p.add(bPanel,BorderLayout.SOUTH); //        ArrayList a = new ArrayList();        for(int i=0;i<lmRoot.size();i++) {          if(lbRoot.getSelectionModel().isSelectedIndex(i)) {            a.add(Roots[i]);          }        }        Object[] o = a.toArray();        //File[] ff= (File[]) a.toArray();        ScanComputer sc = new ScanComputer(o, sfcs.fc.tfStore.getText());        sc.addReporter(new Report() {          public void action(String msg) {            taReport.append(msg);            taReport.setCaretPosition(taReport.getText().length());            repaint();          }        });        sc.addStore(new Report () {          public void action(String msg) {            lmFound.addElement(msg);            repaint();          }        });        sc.addFinish(new Report() {          public void action (String msg) {                      }        });        sc.start();      }    });  }}

Share this post


Link to post
Share on other sites

I had a problem like that recently. I'm not sure if it's the exact same thing, but try adding this line after you add all the components:

p.updateUI();
Basically it tells the frame that something has changed, and to display the change, so the stuff should show up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.