Jul 20, 2008

Second Layout..

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Second Layout..

kvarnerexpress
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...



CODE

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();
     }
   });
 }
}

 

 

 


Reply

beeseven
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:
CODE
p.updateUI();

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

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : layout


    Looking for layout

Searching Video's for layout
advertisement



Second Layout..



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE