0

I have a probleme just when i want to fill Object[] [] : every think work well:

i commted the code for show you the probleme in

I have a probleme just when i want to fill Object[] [] : every think work well: i commted the code for show you the probleme in

String[] columnNames = {"First Name"};

    Object[][] data = {
            {"Kathy"}
        };

    JButton btnConsulter = new JButton("Consulter");
    btnConsulter.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            int i=0;
            // columnNames
            String sql="SELECT DISTINCT idlig FROM `horaire` WHERE nomstation='"+ comboBox.getSelectedItem() +"'";
            ds.Extraction(sql);
            try {
                while(ds.getRs().next()){
                    columnNames[i]=ds.getRs().getString(1);
                    //System.out.println(columnNames[i]);
                    i++;

                }
                //here I want : for every column fill data
                int b=0,j=0;
                for(j=0;j<columnNames.length;j++){
                    sql="SELECT heure FROM `horaire` WHERE idlig="+ columnNames[j]+" AND `nomstation`='"+ comboBox.getSelectedItem() +"'";
                    System.out.println(sql);
                    ds.Extraction(sql);

                    while(ds.getRs().next()){
                        data[b][j]=ds.getRs().getString(1);  // this is the probleme
                        System.out.println(b+"  "+ds.getRs().getString(1)); // its work good with simple display
                        b++;
                    }
                }
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(62, 115, 457, 113);
                contentPane.add(scrollPane);
                table = new JTable(data, columnNames);
                scrollPane.setViewportView(table);

            }catch(Exception e){
                JOptionPane.showMessageDialog(null, "chargement station "+e, "Erreur", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnConsulter.setBounds(468, 22, 89, 23);
    contentPane.add(btnConsulter);
alex2410
  • 10,904
  • 3
  • 25
  • 41

1 Answers1

1

I found some problem in your code's,maybe because this you got error

First: you need to add JTable to JScrollPane and then add JScrollPane to JPanel but you do this:

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(62, 115, 457, 113);
contentPane.add(scrollPane);
table = new JTable(data, columnNames);
scrollPane.setViewportView(table);

also you can use this way by call rePaint() and reValidate() ,methods in JPanel.

Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27
  • sorry its not that the probleme because i use windows builder and it word well, i m searching for how to fiil Object [] [] from a query – hakim el massari Dec 26 '14 at 13:47