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

    problemi con jtable: inserimento dati da db e aggiornamento

    ho problemi nel popolare una jtable... all'apertura della classe do in input un valore intero che dovrebbe identificare la classe di oggetti da recuperare per popolare la jtable... il problema è che all'apertura della classe, la tabella risulta vuota in quanto il valore in input risulta 0.

    la stessa cosa è per l'aggiornamento della jtable... elimino i valodi da DB tramite funzioni e non riesco a far aggiornare il contenuto della jtable... per favore, aiutatemi... ci sto sbattendo la testa da una settimana...

  2. #2
    ecco il codice della classe... aiuto plis

    Codice PHP:
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.GridBagConstraints;
    import javax.swing.JDialog;
    import javax.swing.BorderFactory;
    import java.awt.Font;
    import java.awt.Dimension;
    import javax.swing.JLabel;
    import java.awt.ComponentOrientation;
    import javax.swing.border.EtchedBorder;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    import javax.swing.table.TableModel;
    import javax.swing.JButton;
    import java.awt.BorderLayout;
    import javax.swing.JScrollPane;
    import java.awt.Color;
    import java.util.Vector;

    import javax.swing.JList;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;



    public class 
    GestioneProgrammi extends JFrame {

        private 
    JPanel jContentPane null;

        private 
    JPanel jPanel null;

        private 
    JPanel jPanel1 null;

        private 
    JLabel jLabel null;

        private 
    JLabel jLabel1 null;

        private 
    JPanel jPanel2 null;

        private 
    JButton jButton null;

        private 
    JButton jButton1 null;

        private 
    JButton jButton2 null;

        private 
    JLabel jLabel4 null;

        private 
    JLabel jLabel5 null;

        
    String Titoli[] = {"id_insegnamento""Insegnamento""id_programmi"};
        
        public 
    int riga 0;
        
        public 
    int id_programma 0;
        
        public 
    int id_insegnamento 0;
        
        public 
    int id_docente 0;

        
    /**
         * This is the default constructor
         */
        
    public GestioneProgrammi(int id) {
            
    super();
            
    id_docente id;
            
    initialize();

        }


        private 
    void initialize() {
            
    this.setContentPane(getJContentPane());
            
    this.setTitle("Schedule");
            
    this.setSize(new Dimension(642432));
            
    this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            
    this.setResizable(false);

        }

        
    /**
         * This method initializes jContentPane
         * 
         * @return javax.swing.JPanel
         */
        
    private JPanel getJContentPane() {
            if (
    jContentPane == null) {
                
    jContentPane = new JPanel();
                
    jContentPane.setLayout(new BorderLayout());
                
    jContentPane.add(getJPanel(), BorderLayout.NORTH);
                
    jContentPane.add(getJPanel1(), BorderLayout.CENTER);
            }
            return 
    jContentPane;
        }

        
        
    /**
         * This method initializes jPanel    
         *     
         * @return javax.swing.JPanel    
         */
        
    private JPanel getJPanel() {
            if (
    jPanel == null) {
                
    GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
                
    gridBagConstraints13.gridx 0;
                
    gridBagConstraints13.ipady 30;
                
    gridBagConstraints13.gridy 1;
                
    jLabel5 = new JLabel();
                
    jLabel5.setText("Selezionare l'insegnamneto sul quale effettaure le operazioni.");
                
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
                
    gridBagConstraints.ipady 0;
                
    jLabel = new JLabel();
                
    jLabel.setText("Gestione dei Programmi Didattici");
                
    jLabel.setFont(new Font("Dialog"Font.BOLD24));
                
    jPanel = new JPanel();
                
    jPanel.setLayout(new GridBagLayout());
                
    jPanel.add(jLabelgridBagConstraints);
                
    jPanel.add(jLabel5gridBagConstraints13);
            }
            return 
    jPanel;
        }

        
    /**
         * This method initializes jPanel1    
         *     
         * @return javax.swing.JPanel    
         */
        
    private JPanel getJPanel1() {
            if (
    jPanel1 == null) {
                
    GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
                
    gridBagConstraints19.gridx 7;
                
    gridBagConstraints19.fill GridBagConstraints.HORIZONTAL;
                
    gridBagConstraints19.anchor GridBagConstraints.NORTH;
                
    gridBagConstraints19.gridy 9;
                
    GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
                
    gridBagConstraints18.gridx 7;
                
    gridBagConstraints18.gridy 8;
                
    Modulo = new JLabel();
                
    Modulo.setText("Modulo Consigliato");
                
    GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
                
    gridBagConstraints17.gridx 7;
                
    gridBagConstraints17.fill GridBagConstraints.HORIZONTAL;
                
    gridBagConstraints17.gridy 6;
                
    GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
                
    gridBagConstraints16.gridx 7;
                
    gridBagConstraints16.gridy 7;
                
    jLabel42 = new JLabel();
                
    jLabel42.setText("       ");
                
    GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
                
    gridBagConstraints15.fill GridBagConstraints.BOTH;
                
    gridBagConstraints15.gridy 2;
                
    gridBagConstraints15.weightx 1.0;
                
    gridBagConstraints15.weighty 1.0;
                
    gridBagConstraints15.gridwidth 5;
                
    gridBagConstraints15.gridheight 8;
                
    gridBagConstraints15.gridx 1;
                
    GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
                
    gridBagConstraints14.gridx 8;
                
    gridBagConstraints14.gridheight 8;
                
    gridBagConstraints14.gridy 2;
                
    jLabel41 = new JLabel();
                
    jLabel41.setText("       ");
                
    GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
                
    gridBagConstraints12.gridx 0;
                
    gridBagConstraints12.gridwidth 8;
                
    gridBagConstraints12.gridy 10;
                
    jLabel124 = new JLabel();
                
    jLabel124.setText("          ");
                
    GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
                
    gridBagConstraints3.gridx 2;
                
    gridBagConstraints3.gridwidth 7;
                
    gridBagConstraints3.gridy 1;
                
    jLabel121 = new JLabel();
                
    jLabel121.setText("          ");
                
    GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
                
    gridBagConstraints2.gridx 6;
                
    gridBagConstraints2.fill GridBagConstraints.NONE;
                
    gridBagConstraints2.gridy 2;
                
    jLabel4 = new JLabel();
                
    jLabel4.setText("       ");
                
    GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
                
    gridBagConstraints11.gridy 2;
                
    GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
                
    gridBagConstraints9.gridx 7;
                
    gridBagConstraints9.fill GridBagConstraints.HORIZONTAL;
                
    gridBagConstraints9.anchor GridBagConstraints.CENTER;
                
    gridBagConstraints9.gridy 5;
                
    GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
                
    gridBagConstraints8.gridx 7;
                
    gridBagConstraints8.fill GridBagConstraints.HORIZONTAL;
                
    gridBagConstraints8.gridy 3;
                
    GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
                
    gridBagConstraints7.gridx 7;
                
    gridBagConstraints7.fill GridBagConstraints.HORIZONTAL;
                
    gridBagConstraints7.gridy 2;
                
    GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
                
    gridBagConstraints1.gridx 6;
                
    gridBagConstraints1.gridy 8;
                
    jLabel1 = new JLabel();
                
    jLabel1.setText("       ");
                
    jPanel1 = new JPanel();
                
    jPanel1.setLayout(new GridBagLayout());
                
    jPanel1.add(jLabel1gridBagConstraints11);
                
    jPanel1.add(getJPanel2(), gridBagConstraints1);
                
    jPanel1.add(getJButton(), gridBagConstraints7);
                
    jPanel1.add(getJButton1(), gridBagConstraints8);
                
    jPanel1.add(getJButton2(), gridBagConstraints9);
                
    jPanel1.add(jLabel4gridBagConstraints2);
                
    jPanel1.add(jLabel121gridBagConstraints3);
                
    jPanel1.add(jLabel124gridBagConstraints12);
                
    jPanel1.add(jLabel41gridBagConstraints14);
                
    jPanel1.add(getJScrollPane(), gridBagConstraints15);
                
    jPanel1.add(jLabel42gridBagConstraints16);
                
    jPanel1.add(getJButton3(), gridBagConstraints17);
                
    jPanel1.add(ModulogridBagConstraints18);
                
    jPanel1.add(getJButton4(), gridBagConstraints19);
            }
            return 
    jPanel1;
        }

        
    /**
         * This method initializes jPanel2    
         *     
         * @return javax.swing.JPanel    
         */
        
    private JPanel getJPanel2() {
            if (
    jPanel2 == null) {
                
    jPanel2 = new JPanel();
                
    jPanel2.setLayout(new GridBagLayout());
            }
            return 
    jPanel2;
        }

        
    /**
         * This method initializes jButton    
         *     
         * @return javax.swing.JButton    
         */
        
    private JButton getJButton() {
            if (
    jButton == null) {
                
    jButton = new JButton();
                
    jButton.setText("Aggiungi");
                
    jButton.setPreferredSize(new Dimension(17526));
                
    jButton.addActionListener(new java.awt.event.ActionListener() {
                    public 
    void actionPerformed(java.awt.event.ActionEvent e) {
                        
    scv.RichiestaApriInserimentoProgramma(id_insegnamento); 
                    }
                });
            }
            return 
    jButton;
        }

        
    /**
         * This method initializes jButton1    
         *     
         * @return javax.swing.JButton    
         */
        
    private JButton getJButton1() {
            if (
    jButton1 == null) {
                
    jButton1 = new JButton();
                
    jButton1.setText("Modifica");
                
    jButton1.setPreferredSize(new Dimension(17526));
                
    jButton1.addActionListener(new java.awt.event.ActionListener() {
                    public 
    void actionPerformed(java.awt.event.ActionEvent e) {
                        
                    }
                });
            }
            return 
    jButton1;
        }

        
    /**
         * This method initializes jButton2    
         *     
         * @return javax.swing.JButton    
         */
        
    private JButton getJButton2() {
            if (
    jButton2 == null) {
                
    jButton2 = new JButton();
                
    jButton2.setText("Elimina");
                
    jButton2.setPreferredSize(new Dimension(17526));
                
    jButton2.addActionListener(new java.awt.event.ActionListener() {
                    public 
    void actionPerformed(java.awt.event.ActionEvent e) {
                        
                    }
                });
            }
            return 
    jButton2;
        }

        
    TableModel model =
              new 
    DefaultTableModel(GestioneProgrammi.this.PopolaTabella(GestioneProgrammi.this.id_docente), Titoli) {
                public 
    boolean isCellEditable(int xint y) {
                  return 
    false;
                }
                
              };

        private 
    JLabel jLabel121 null;

        private 
    JLabel jLabel124 null;

        private 
    JLabel jLabel41 null;

        private 
    JScrollPane jScrollPane null;

        private 
    JTable jTable1 null;

        private 
    JLabel jLabel42 null;

        private 
    JButton jButton3 null;

        private 
    JLabel Modulo null;

        private 
    JButton jButton4 null;


        
    /**
         * This method initializes jScrollPane    
         *     
         * @return javax.swing.JScrollPane    
         */
        
    private JScrollPane getJScrollPane() {
            if (
    jScrollPane == null) {
                
    jScrollPane = new JScrollPane();
                
    jScrollPane.setViewportView(getJTable1());
            }
            return 
    jScrollPane;
        }
        public 
    String [][] PopolaTabella(int id_docente){
            if (
    id_docente == 0){
                
    System.out.println("id docente è vuoto");
                return 
    null;
            }else{
            
    Vector v=scv.RichiestaVisualizzazioneElencoProgrammi(id_docente);
            
    int i=0;
            
    String dati[][] = new String[v.size()][3];
            while ( 
    i<v.size() ) {
               
    String [] record = (String[]) v.elementAt(i);
               for (
    int j=0j<2j++){
                  
    dati[i][j] = record [j];
               }

               for (
    int j=2j<3j++){
                   if (
    record[j].equals("null")){
                       
    dati[i][j] = "0";
                   }else {
                       
    dati[i][j] = record[j];
                   }
               }
               
    i++;
            }
            return 
    dati;
            }
        }
        
    /**
         * This method initializes jTable1    
         *     
         * @return javax.swing.JTable    
         */
        
    private JTable getJTable1() {
            if (
    jTable1 == null) {
                
    jTable1 = new JTable(model);
                        
    TableColumnModel colModel jTable1.getColumnModel();
                        
    TableColumn col0 colModel.getColumn(0);
                        
    TableColumn col2 colModel.getColumn(2);
                        
    jTable1.removeColumn(col0);
                        
    jTable1.removeColumn(col2);
                        
    jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
                            public 
    void mouseClicked(java.awt.event.MouseEvent e) {
                                try {
                                    
    clickRiga(e);
                                } catch (
    Exception f) {
                                    
    System.out.println(f.getStackTrace());
                                    
    System.out.println(f.getMessage());
                                }
                            }
                        });
                
            }
            return 
    jTable1;
        }
        
        private 
    void clickRiga(java.awt.event.MouseEvent evtthrows Exception {
            try {
                
    String [][] dati PopolaTabella(id_docente);
                if (
    evt.getClickCount() < 2){
                    
    riga jTable1.getSelectedRow();
                    
    id_programma Integer.parseInt(dati[riga][2]);
                    
    id_insegnamento Integer.parseInt(dati[riga][0]);
                }            
            } catch (
    Exception f) {
                
    System.out.println(f.getStackTrace());
                
    System.out.println(f.getMessage());
            }
        }
        
        private 
    void eliminaProgramma (int id_programma){
            
    int ret JOptionPane.showConfirmDialog (null,"Sei sicuro di voler eliminare " +
                    
    "questo programma?""Schedule"JOptionPane.YES_NO_OPTION );
            if (
    ret == JOptionPane.YES_OPTION){
                
    scv.RichiestaEliminaProgramma(id_programma);
                }
            
        }
        
    /**
         * This method initializes jButton3    
         *     
         * @return javax.swing.JButton    
         */
        
    private JButton getJButton3() {
            if (
    jButton3 == null) {
                
    jButton3 = new JButton();
                
    jButton3.setText("Visualizza");
                
    jButton3.addActionListener(new java.awt.event.ActionListener() {
                    public 
    void actionPerformed(java.awt.event.ActionEvent e) {
                        
                    }
                });
            }
            return 
    jButton3;
        }

        
    /**
         * This method initializes jButton4    
         *     
         * @return javax.swing.JButton    
         */
        
    private JButton getJButton4() {
            if (
    jButton4 == null) {
                
    jButton4 = new JButton();
                
    jButton4.setText("Download");
                
    jButton4.addActionListener(new java.awt.event.ActionListener() {
                    public 
    void actionPerformed(java.awt.event.ActionEvent e) {
                        
                    }
                });
            }
            return 
    jButton4;
        }

        public static 
    void main (String args[]){
            new 
    GestioneProgrammi(1).setVisible(true);
        }



  3. #3
    nessuno riesce ad aiutarmi? nemmeno per l'aggiornamento della tabella?

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.