Page 1 of 2 12 LastLast
Results 1 to 20 of 21
Like Tree1Likes

Thread: load Jtable

  1. #1
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default load Jtable

    Hello,
    i have 2 jframe : First and Second.
    the first contains boutton Rechercher.
    the second contains JTable.
    it's possible to load a data from database when i clik Rechercher?

    Thanks

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: load Jtable

    Yes, it's possible.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    i will give you my code , if u can help please , this problem bloked me before 2 week.
    my first jframe contains button Valider and Jtable1 , this is the code of Valider.
    u will find join a picture of my interface
    Java Code:
    Second sec = new Second();
    sec.show();
    the second contain buton Rechercher and jtable1, the code of Recherche do the insert into table in database from Jtable2 and reload jtable1
    this is code of buton Rechercher
    Java Code:
    private void AjouterActionPerformed(java.awt.event.ActionEvent evt) {    
                try {      
    // le numéro de la ligne selectionée
    int i = jTable2.getSelectedRow(); 
    //récuperation des données 
    String selt1 = jTable2.getValueAt(i, 0).toString(); 
    String selt2=jTable2.getValueAt(i, 1).toString();  
     //Insertion in DATABASE (in table A)
     con.Conn().executeUpdate("insert into A values ('"+selt1+"','"+selt2+"')");          
     // reload jtable1 of the first jframe
     First fs = new First();
    ResultSet ResultRech = null;
    DefaultTableModel aModel = (DefaultTableModel) fs.jTable1.getModel();
    aModel.getDataVector().removeAllElements();
       {   
    ResultRech = con.Conn().executeQuery("select * from A");           
     ResultSetMetaData rsmd = null;
        rsmd = ResultRech.getMetaData();
          int cols = 0;
            cols = rsmd.getColumnCount();
             while (ResultRech.next())
      {
    Object[] row = new Object[cols];
     for (int j = 0; j < row.length; j++) {
       row[j] = ResultRech.getObject(j + 1);               
     }
    aModel.addRow(row);
    }
    fs.jTable1.setModel(aModel);
     fs.jTable1.repaint();
       this.dispose();//close the  Second jframe
     }}catch (SQLException | RemoteException ex) {
    Logger.getLogger(B.class.getName()).log(Level.SEVERE, null, ex);
    }
    this code of reload run 100 % when i put it in buton in the same jframe of jtable, but when i put it in another jframe , it dind't run.
    load Jtable-prin.png

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: load Jtable

    CardLayout.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    how i can use CardLayout here

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: load Jtable

    Wow, you've read the CardLayout tutorial in 16 minutes?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    Sorry , i am beginner in Netbeans so i don't have a big informations.
    for the CardLayout : i know just we can used it in 1 jframe and 2 jpanel or more , but i don't know use it with 2 jframe.
    give a link if u have a tutorial to use CardLayout with many Jframe.
    Thanks

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: load Jtable

    The idea is to use one JFrame and the CardLayout within that. And I'm sure you're able to use Google for a tutorial yourself.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    thanks for your help but because i'm beginner i will find solution for this porblem after 1 month
    Last edited by Ridha; 01-30-2013 at 05:37 PM.

  10. #10
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    we can't did reload of jtable with cardlayout , u have another idea please ?

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: load Jtable

    Reload of JTable? setModel(...)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #12
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: load Jtable

    I get the feeling that the OP is trying a reload via LayoutManager or something strange
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  13. #13
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    @DarrylBurke : i put setModel() in my code, i'm sure that u are not understand my problem and i tell in the start of thread my code of reload run 100% when i put the code in the same jframe of jtable.
    my problem : i have problem in reload of jtable1(exist in the first jframe and it load data from database)after insert by jtable2(exist in the second jframe ) and this second jframe contain also a boutton rechercher to do the insert into database from the jtable2 and to reload jtable1.(Note : the first jframe is always open meaning i don't need option .show() (to show the first jframe) in the code of button rechercher , this is why the code of relaod don't run)
    Last edited by Ridha; 02-01-2013 at 03:52 PM.

  14. #14
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    306
    Rep Power
    6

    Default Re: load Jtable

    Are you trying to have the button on the 2nd JFrame reload the information on the 1st JFrame?

  15. #15
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    yes , the bouton Rechercher do insert into database and reload of first Jframe

  16. #16
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    306
    Rep Power
    6

    Default Re: load Jtable

    I'm confused, I see a constructor in the actionPerformed() for a new First instance. Is the First class the 1st JFrame? I don't see that instance being displayed/made visible, is that a different instance then the one you want to display on?

  17. #17
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    the first jframe is already displayed, when i clik in buton valider , the second jframe will be displayed .
    after that when i clik in one row of jtable2 and i clik rechercher , this row will be inserted in the database and the second jframe will be closed and reload jtable1 (to show the new insert)

  18. #18
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    306
    Rep Power
    6

    Default Re: load Jtable

    Then why are you creating a new First instance and manipulating the table there? If there is another one already displayed, you should be using that instance.

    Is there any connection between the First frame and the Second? Does the Second Frame take in a First as a constructor parameter or anything?
    DarrylBurke likes this.

  19. #19
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    sorry , but i did mistake in actionperformed, this code is in button Rechercher
    Java Code:
    private void RechercherActionPerformed(java.awt.event.ActionEvent evt) {   
                try {     
    // le numéro de la ligne selectionée
    int i = jTable2.getSelectedRow();
    //récuperation des données
    String selt1 = jTable2.getValueAt(i, 0).toString();
    String selt2=jTable2.getValueAt(i, 1).toString(); 
     //Insertion in DATABASE (in table A)
     con.Conn().executeUpdate("insert into A values ('"+selt1+"','"+selt2+"')");         
     // reload jtable1 of the first jframe
     First fs = new First();
    ResultSet ResultRech = null;
    DefaultTableModel aModel = (DefaultTableModel) fs.jTable1.getModel();
    aModel.getDataVector().removeAllElements();
       {  
    ResultRech = con.Conn().executeQuery("select * from A");          
     ResultSetMetaData rsmd = null;
        rsmd = ResultRech.getMetaData();
          int cols = 0;
            cols = rsmd.getColumnCount();
             while (ResultRech.next())
      {
    Object[] row = new Object[cols];
     for (int j = 0; j < row.length; j++) {
       row[j] = ResultRech.getObject(j + 1);              
     }
    aModel.addRow(row);
    }
    fs.jTable1.setModel(aModel);
     fs.jTable1.repaint();
       this.dispose();//close the  Second jframe
     }}catch (SQLException | RemoteException ex) {
    Logger.getLogger(B.class.getName()).log(Level.SEVERE, null, ex);
    }
    @StormyWaters : i do new first instance(First fs = new First();) to will be have a access for the jtable1 in the first jframe.
    the connection between first jframe and the second is in button valider
    Java Code:
     Second sec = new Second();
    sec.show();
    Last edited by Ridha; 02-02-2013 at 08:17 AM.

  20. #20
    Ridha is offline Member
    Join Date
    Jan 2013
    Posts
    28
    Rep Power
    0

    Default Re: load Jtable

    If there is another one already displayed, you should be using that instance.
    how i can use the instance ?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 04-02-2012, 07:57 PM
  2. could not load load from location:/test_subreport.jasper
    By jadeite100 in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 03-27-2012, 11:43 AM
  3. Adding New JTable in JTable
    By anilkumar_vist in forum New To Java
    Replies: 0
    Last Post: 01-27-2010, 08:27 AM
  4. Replies: 0
    Last Post: 12-04-2008, 05:39 PM
  5. Replies: 2
    Last Post: 05-15-2008, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •