Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Passare un arrayList ad un Jframe

    Ciao a tutti, vi spiego il mio problema.

    Ho una classe che estende la classe JFrame chiamata EntryFrame. (public class EntryFrame extends javax.swing.JFrame)

    questa classe contiene un ArrayList di un oggetto chiamato property. (private ArrayList<Property> properties

    Un altro JFrame (public class ViewerFrame extends javax.swing.JFrame) contiene una JTextArea nella quale vorrei mostrare i dati dell'arrayList (che ricordo si trova nell'altra classe).
    Ho provato a passare l'arrayList tramite il costruttore della classe ViewerFrame ma la jTextArea risulta vuota.

    Any idea???

    Cliccando il tasto di cui riporto l'evento l'evento apro l'altra classe jframe.
    codice:
        private void ViewButtonActionPerformed(java.awt.event.ActionEvent evt)              {                                           
        ViewerFrame.main(null);          
            
        }

    Questa è la classe del JFrame che contiene la JTextArea.

    codice:
    package monashrealestateagency;
    
    import java.util.ArrayList;
    
    /**
     *
     * @author DARIO
     */
    public class ViewerFrame extends javax.swing.JFrame {
        
    private ArrayList<Property> properties;
        
        /** Creates new form ViewerFrame */
        public ViewerFrame() {
            super();
            initComponents();
            }
        
        public ViewerFrame(ArrayList<Property> properties) {
            initComponents();
            this.properties = properties;
            int i = 0;
            while (i<properties.size())
            {
            jTextArea1.append(properties.get(i).getAddress());
            }
        }
        
        private void displayData(ArrayList<Property> properties)
        {
        int i = 0;
           while (i < properties.size())
           {
           jTextArea1.append(properties.get(i).getAddress());
           }
        }  
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
    
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(193, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new ViewerFrame().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        // End of variables declaration
    }

    Grazie in anticipo e scusate se rompo spesso.
    Ciao

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2009
    Messaggi
    1,123
    Scusa ma non ho tempo nemmeno per guardare il source.
    Il consiglio che posso darti è guardare nella classe che riceve l'ArrayList, se questo contiene elementi (metti un for ed un System.out.println(), e stampali a video).
    Se li contiene, probabilmente sbaglierai il modo in cui li estrai e li inserisci nell'area di testo.

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    scusa ma non hai eccezioni??
    codice:
    while (i<properties.size()){
            jTextArea1.append(properties.get(i).getAddress());
            }
    è praticamente un ciclo infinito, prima o poi dovresti avere un'eccezione qualsiasi.

    in genere si fa

    codice:
    for (int index = 0; index < properties.size(); index++){
              area.append(proprerties.get(index).getAddress());
      }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.