9 Replies - 455 Views - Last Post: 03 March 2013 - 04:56 PM Rate Topic: -----

#1 supupoff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-February 13

two questions about jTable.

Posted 01 March 2013 - 12:53 AM

Hi,
i have two questions about jTable. :nottalkingtoyou:

Question 1 :
i have a boolean column (etat) in table projet in database, can i show this column in jTable? cause i do for all other columns, but not for this column it shows me some carractors and numbers,!!

Question 2

Also in table projet i have two columns, ( namepdf, filepdf ) can i show in some lines in jtable the pdf file as link to save on desktop , i can do it on JButton but not i jTable,! i do search on google but nothing

please help, :helpsmilie:
Thanks a lot

Is This A Good Question/Topic? 0
  • +

Replies To: two questions about jTable.

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,988
  • Joined: 20-September 08

Re: two questions about jTable.

Posted 01 March 2013 - 04:45 AM

1.

Quote

but not for this column it shows me some carractors and numbers,!!

How are you creating your TableModel? If you want a boolean column, it's usually better to override getColumnClass to return Boolean. You'll then see a checkbox in the table

2. Google on 'custom CellRenderer java' and 'custom CellEditor java'. You could render and edit with a JButton carrying a link.

It rather depends on whether the whole JTable is read-only
Was This Post Helpful? 0
  • +
  • -

#3 supupoff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-February 13

Re: two questions about jTable.

Posted 02 March 2013 - 04:39 AM

View Postg00se, on 01 March 2013 - 04:45 AM, said:

1.

Quote

but not for this column it shows me some carractors and numbers,!!

How are you creating your TableModel? If you want a boolean column, it's usually better to override getColumnClass to return Boolean. You'll then see a checkbox in the table

2. Google on 'custom CellRenderer java' and 'custom CellEditor java'. You could render and edit with a JButton carrying a link.

It rather depends on whether the whole JTable is read-only


Thanks a lot for help, i do try to follow what you said. but cause its my first time i work on 'custom CellRenderer java' and 'custom CellEditor java', i cant give it up. so if you can help me in the begenin

i have this methode that should return a Jtable and it work,

public void ListeAlll(){
    
    DefaultTableModel tabla = new DefaultTableModel();
    Activiter ac = new Activiter();
    ArrayList<Activiter> lista2 = new ArrayList();
    lista2 = ac.ListeAll();
    tabla.addColumn("Nom");
    tabla.addColumn("Prenom");
    ....
    ....
    tabla.setRowCount(lista2.size());
     
    int i=0;
    for (Activiter x : lista2){
     
        tabla.setValueAt(x.getnom(), i, 0);
        tabla.setValueAt(x.getprenom(), i, 1);
        ...

        i++;
      // 
}
    this.jTable2.setModel(tabla);

}



here i want to add another column that shows a link to save pdf on desktop !
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,988
  • Joined: 20-September 08

Re: two questions about jTable.

Posted 02 March 2013 - 06:59 AM

How does a boolean come into 'Nom' and 'Prenom'?
Was This Post Helpful? 0
  • +
  • -

#5 supupoff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-February 13

Re: two questions about jTable.

Posted 02 March 2013 - 01:09 PM

View Postg00se, on 02 March 2013 - 06:59 AM, said:

How does a boolean come into 'Nom' and 'Prenom'?

here i talk about pdf and show it as a link,

Quote

Question 2

Also in table projet i have two columns, ( namepdf, filepdf ) can i show in some lines in jtable the pdf file as link to save on desktop , i can do it on JButton but not i jTable,! i do search on google but nothing

Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,988
  • Joined: 20-September 08

Re: two questions about jTable.

Posted 02 March 2013 - 04:39 PM

So what happened to the boolean about which you were asking?
Was This Post Helpful? 0
  • +
  • -

#7 supupoff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-February 13

Re: two questions about jTable.

Posted 03 March 2013 - 01:38 AM

View Postg00se, on 02 March 2013 - 04:39 PM, said:

So what happened to the boolean about which you were asking?


didnt work on it yeat, i stil try to finish work on Button as PDF links i do this,

i use this topic ButtonColumn


ButtonColumn buttonColumn = new ButtonColumn(this.jTable1,BTN,7);

 
Action  BTN= new AbstractAction() 
{
    public void actionPerformed(ActionEvent e)
    {
         JTable jTable1 = (JTable)e.getSource();
       
        action();
    }
};
  public void action() // charger PDF from dataBase
  {
       int rec = this.jTable1.getSelectedRow();
        // JFileChooser JFileChooser = new JFileChooser(".");
        JFileChooser JFileChooser = new MyFileChooser(".", "pdf");
        Activiter ac = new Activiter();

        int status = JFileChooser.showDialog(null,"Enregistrer");

        if(status == JFileChooser.APPROVE_OPTION)
        {
            try
            {

                ac.chargeIMG(jTable1.getValueAt(rec, 4).toString(),JFileChooser.getSelectedFile().getAbsolutePath());
            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(null,"Une erreur s'est produite dans le chargement de documents.");
                ex.printStackTrace();
            }
        }
  }



i have a button in Colmn 7 in Jtable but, i want to add a text or a icon, i do not know how do it,!?
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: two questions about jTable.

Posted 03 March 2013 - 01:22 PM

    public void actionPerformed(ActionEvent e)
    {
        // what is the use of creating that local variable jTable1.
        JTable jTable1 = (JTable)e.getSource();
        // you don't use it anywhere
       
        action();
    } // <--- jTable1 stop to exists starting from here


Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,988
  • Joined: 20-September 08

Re: two questions about jTable.

Posted 03 March 2013 - 01:29 PM

Quote

i want to add a text or a icon, i do not know how do it,!?
You're saying you don't know how to set the text of a JButton??
Was This Post Helpful? 0
  • +
  • -

#10 supupoff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-February 13

Re: two questions about jTable.

Posted 03 March 2013 - 04:56 PM

View Postg00se, on 03 March 2013 - 01:29 PM, said:

Quote

i want to add a text or a icon, i do not know how do it,!?
You're saying you don't know how to set the text of a JButton??

I know how :nottalkingtoyou: not like that i mean. fallen leaves i find the solution. i create a class ActionEx and i use imageIcon
----------------
5ritou fih :D

View Postpbl, on 03 March 2013 - 01:22 PM, said:

    public void actionPerformed(ActionEvent e)
    {
        // what is the use of creating that local variable jTable1.
        JTable jTable1 = (JTable)e.getSource();
        // you don't use it anywhere
       
        action();
    } // <--- jTable1 stop to exists starting from here



Yes you are right :sweatdrop: , thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1