[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13289
  • Last Modified:

refresh Jtable


Hello there,

I have a JTable with database records in it.when i add a new record i want to reload the table dynamically to show the new record,instead of closing and opening the frame again to show the new record.

these are the class and methods that is responsible for the jtable
this is the constr of the class where the table is

public TreeTableInternalFrame(final PictMenuFrameDemo frame)
    {
        super("InternalFrame",
              true, //resizable
              true, //closable
              true, //maximizable
              true);//iconifiable

        Dimension deskSize = frame.getDesktop().getSize();
        setSize((int)deskSize.getWidth() - 20, (int)deskSize.getHeight() - 20);
        //Set the window's location.
        setLocation(10, 10);
        JFParentFrame = frame;
        //get database result in to collections
        initCollections(frame.getDBConnection());
       
        testIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/dslamIcon.png"));
       
         cityIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/cityIcon.png"));
         coIcon =  new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/coIcon.png"));
         dslamIcon =  new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/dslamIcon.png"));
         linecardIcon =  new ImageIcon(Toolkit.getDefaultToolkit().createImage("images/cardIcon.png"));

       
        //set layout for frame content panel
        Container cp = getContentPane();
        cp.setLayout(new BorderLayout());
       
        //create toolbar
        JToolBar toolbar = createToolbar();
        cp.add(toolbar, BorderLayout.NORTH);

        // create popup menu for tree
        //treePopupMenu = createPopupMenuDslam();
       
        // create tree element
        createAndInitTree();
             
        JScrollPane jsp = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
       
       
        //create tab panel
        tabPane = new JTabbedPane();
       
        cityPane = new JPanel(new BorderLayout());
       
        createCityTable();

        jspCity = new JScrollPane(cityTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        cityPane.add(jspCity, BorderLayout.CENTER);
        tabPane.addTab("  City  ", cityIcon, cityPane);
       
        JPanel coPane = new JPanel(new BorderLayout());
        createCoTable();
        JScrollPane jspCo = new JScrollPane(coTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        coPane.add(jspCo, BorderLayout.CENTER);
        tabPane.addTab("   Co   ", coIcon, coPane);
       
        JPanel dslamPane = new JPanel(new BorderLayout());
        createDslamTable();
        JScrollPane jspDslam = new JScrollPane(dslamTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        dslamPane.add(jspDslam, BorderLayout.CENTER);
        tabPane.addTab("  Dslam  ", dslamIcon, dslamPane);
       
       
        JPanel linecardPane = new JPanel(new BorderLayout());
        createlinecardTable();
        JScrollPane jspLinecard = new JScrollPane(linecardTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        linecardPane.add(jspLinecard, BorderLayout.CENTER);
        tabPane.addTab("  Linecard  ", linecardIcon, linecardPane);
               
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp, tabPane);
        cp.add(splitPane, BorderLayout.CENTER);
       
        addInternalFrameListener(new InternalFrameAdapter() {
             public void internalFrameClosing(InternalFrameEvent ife) {
                  frame.setInnerFrameNull();  
             }
        });
    }

and this is the method in the above class which is called in another class when i enter new data to be saved in db

public void reloadRecord()
    {
         initCollections(JFParentFrame.getDBConnection());
         //javax.swing.JOptionPane.showMessageDialog(null, "Called");
         createCityTable();
         cityPane.revalidate();
         cityPane.repaint();
    }


and this is the method which is called the first time in the constr of the above class and the second time it is called in the reloadRecord method

private void createCityTable()
    {
         System.out.println("Inside createCityTable() ");
         if (cityTable==null)
         {
            String[] columnNames = {"City ID",
                       "City Farsi Name",
                       "City English Name",
                       "Prefix"};
            model = new DefaultTableModel(columnNames, 0);
           
            for (int i = 0; i < cityCollect.size(); i++)
            {
                 DefaultMutableTreeNode node = (DefaultMutableTreeNode)cityCollect.get(i);
                 CityRow row = (CityRow)node.getUserObject();
                 System.out.println("city "+row);
                 model.addRow(new Object[] {row.getCityId(),
                            row.getCityFarsiName(),
                            row.getCityEngName(),
                            row.getPrefix()
                       });
             
            }
           cityTable = new JTable(model);        
           cityTable.getColumnModel().getColumn(0).setMaxWidth(60);
           cityTable.getColumnModel().getColumn(0).setPreferredWidth(60);
           cityTable.getColumnModel().getColumn(3).setMaxWidth(200);
           cityTable.getColumnModel().getColumn(3).setPreferredWidth(200);
           cityTable.setEnabled(false);
         }
         else
         {
            JOptionPane.showMessageDialog(null, "Clearing table");
            cityTable.setModel(new DefaultTableModel());
         }  
         
    }
0
zolf
Asked:
zolf
  • 23
  • 12
  • 8
  • +1
2 Solutions
 
Mayank SAssociate Director - Product EngineeringCommented:
Maybe you need to call fireTableModelChanged ()
0
 
zolfAuthor Commented:

where
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Just noticed you were creating a new table everytime - is that required? I thought you want to add rows to an existing table. In your current code, everytime reloadRecord () is called, it will create new table.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zolfAuthor Commented:

yes i want to add row to an existing table.
what do i need to do then??
pleaseeee help
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You can add it using:

http://javaalmanac.com/egs/javax.swing.table/AppendRow.html

Use table.getModel () to get the table-model.
0
 
zolfAuthor Commented:

actually in the code above,i create the table in TreeTableInternalFrame(final PictMenuFrameDemo frame)
and i am adding into that table from anothe class.
how can i use table.getModel () in that other class to add

te code below is in another class which populates the new record in the db
ActionListener JBActionListener = new ActionListener()
            {
                  public void actionPerformed(ActionEvent e)
                  {
                        String srcObj = e.getActionCommand();
                        
                        if(srcObj=="update")
                        {
                              if(RequiredFieldEmpty()==false)
                              {
                                    if(ADDING_STATE == true)
                                    {
                                          updateCityCollection(OwnerForm.getDBConnection());      
                                                   // Start Display the new record
                                                   int total =0;
                                                   total = clsPublicMethods.getMaxNum("SELECT * FROM city ORDER BY city_id ASC",OwnerForm.getDBConnection(),"city_id");
                                                   
                                                   if(total != 0)
                                                   {
                                                                                                                  System.out.print("TOTAL  1 "+total);
                                                                                                                  
                                                         tf.reloadRecord();
                                                                                                            }


private void updateCityCollection(Connection connect)
            {
                Vector cityCollect = new Vector();
                
                try
                {
                      st = connect.createStatement();
                             String query = "INSERT INTO CITY (CITY_ID,CITY_ENG_NAME,CITY_FARSI_NAME,PREFIX) VALUES (city_id_seq.nextval,'"+JTFCEngName.getText()+"','"+JTFCFarName.getText()+"','"+JTFCPrefix.getText()+"')";
                        st.executeUpdate(query);
                                        }
                catch (SQLException sqle)
                {
                      System.err.println("Can't get city collection from database : " + sqle.getMessage());
                }
          }
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>>how can i use table.getModel () in that other class to add

You need to expose the table using something like:

public JTable getCityTable ()
{
  return table ;
}
0
 
zolfAuthor Commented:

you mean i create a method called

public JTable getCityTable ()
{
  return table ;
}

in my TreeTableInternalFrame(final PictMenuFrameDemo frame) class

and call this method in the other class where i add the row to the db
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yes, whichever class that contains the JTable.
0
 
zolfAuthor Commented:

can you please guide me exactly what i need to do in the code i have posted above.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Add it to the class which has the table. Then in the other class, use:

JTable table = yourInternalFrameObject.getTable () ;

Then follow the code which I posted in the sample.
0
 
zolfAuthor Commented:

the problem is the table is not refreshing.
i did a test where the flag is false the first time i run the application.then i make the flag true the second time.the code comes inside the if loop,but the color does not change.what should i do to refresh.
if(flag)
{
                 System.out.println("INSIDE IF");
                 cityTable.setForeground(Color.GREEN);
                 cityTable.repaint();
                 cityPane.revalidate();
               cityPane.repaint();
               tabPane.repaint();
               tabPane.revalidate();
}
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I would have expected revalidate () to do it. Are you sure the rows were added properly? Can you print the row-count using System.out.println () after the call to revalidate () to make sure the rows were added properly and that its only a problem with teh display?
0
 
zolfAuthor Commented:

i did a System.out.println () after the call to revalidate () and the row was added properly.

if(flag)
 {
                 System.out.println("INSIDE IF");

                 cityTable.setForeground(Color.GREEN);
                 cityTable.repaint();
                 cityPane.revalidate();
               cityPane.repaint();
               tabPane.repaint();
               tabPane.revalidate();

               System.out.println("INSIDE if loop"+cityTable.getRowCount());

  }
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Did you try fireTableModelChanged () ?
0
 
zolfAuthor Commented:

no,where do i add this function after revalidate() ?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try it before revalidate ()
0
 
zolfAuthor Commented:

cityTable.fireTableModelChanged();

it gives error saying not defined for JTable

0
 
zolfAuthor Commented:

i tried this,but the table did not refresh

model.fireTableDataChanged();
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yeah, sorry I meant tableDataChanged.... if that doesn't work, I'm afraid I'm not sure how else it will.
0
 
zolfAuthor Commented:

this there no one to help me sort this problem
0
 
riaancorneliusCommented:
after you add the rows (or make any change to the model), try calling
cityTable.repaintUI();

It's unlikely that it will solve the problem, but if you change some of the renderers, it is sometimes necessary to call updateUI().
0
 
objectsCommented:
>                                                 tf.reloadRecord();

check that tf is the frame that contains your table.
0
 
zolfAuthor Commented:


how can i check that,can you give me some code example
0
 
Mayank SAssociate Director - Product EngineeringCommented:
He means where is tf declared? Is it the correct object (of the class) that has a JTable inside it?
0
 
zolfAuthor Commented:

if you look at my code above in my first comment is the class which creates the table for the first time the application opens.then in my 4th comment,the code which i have put is where i am calling that class again to recreate the table.and that is where i create the object tf of my first class.
#what do i need to do to refer to that table or refresh.
0
 
objectsCommented:
i can't see any line that assigns tf, can you post it again please.
0
 
zolfAuthor Commented:

i create the table in TreeTableInternalFrame(final PictMenuFrameDemo frame) and the code is in my first comment.

i am adding into that table from anothe class.


the code below is in another class which populates the new record in the db
ActionListener JBActionListener = new ActionListener()
          {
               public void actionPerformed(ActionEvent e)
               {
                    String srcObj = e.getActionCommand();
                   
                    if(srcObj=="update")
                    {
                         if(RequiredFieldEmpty()==false)
                         {
                              if(ADDING_STATE == true)
                              {
                                   updateCityCollection(OwnerForm.getDBConnection());      
                                           // Start Display the new record
                                           int total =0;
                                           total = clsPublicMethods.getMaxNum("SELECT * FROM city ORDER BY city_id ASC",OwnerForm.getDBConnection(),"city_id");
                                           
                                           if(total != 0)
                                           {
                                               System.out.print("TOTAL  1 "+total);
                                                                                               
                                                tf.reloadRecord(); //object of the class which creates jtable and shows data
                                           }


private void updateCityCollection(Connection connect)
          {
              Vector cityCollect = new Vector();
             
              try
              {
                   st = connect.createStatement();
                         String query = "INSERT INTO CITY (CITY_ID,CITY_ENG_NAME,CITY_FARSI_NAME,PREFIX) VALUES (city_id_seq.nextval,'"+JTFCEngName.getText()+"','"+JTFCFarName.getText()+"','"+JTFCPrefix.getText()+"')";
                    st.executeUpdate(query);
                                  }
              catch (SQLException sqle)
              {
                   System.err.println("Can't get city collection from database : " + sqle.getMessage());
              }
         }
0
 
objectsCommented:
I didn't ask where you create the table, I am asking where you set tf
Somewhere you must have "tf = ......"
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> if(srcObj=="update")

Should also have if ( srcObj.equals ( "update" ) )
0
 
zolfAuthor Commented:
this is the class below where i making an object called tf of class TreeTableInternalFrame(final PictMenuFrameDemo frame)

public class Frm_add_edit_city extends JDialog
      {
            JButton JBUpdate = new JButton(new ImageIcon("images/save.png"));
            JButton JBReset = new JButton("Reset",new ImageIcon("images/reset.png"));
            JButton JBCancel = new JButton("Cancel",new ImageIcon("images/cancel.png"));
            
            JLabel JLPic1 = new JLabel();
            JLabel JLBanner = new JLabel("Please fill-up all the required fields.");
            
            JLabel JLCEngName = new JLabel("City Name:");
            JLabel JLCFarName = new JLabel("City Name:");
            JLabel JLCPrefix = new JLabel("City Prefix:");
            
            JTextField JTFCEngName = new JTextField();
            JTextField JTFCFarName = new JTextField();
            JTextField JTFCPrefix = new JTextField();
                  
            Dimension screen =       Toolkit.getDefaultToolkit().getScreenSize();
            Statement st;
            boolean ADDING_STATE;
            Connection connect;
            Statement stAEC;
            ResultSet rsAEC;
            PictMenuFrameDemo OwnerForm;
            TreeTableInternalFrame tf;
            
            public Frm_add_edit_city(boolean ADD_STATE,PictMenuFrameDemo OwnerForm)
            {
                  super(OwnerForm,true);
                  tf = new TreeTableInternalFrame(OwnerForm);
                  ////cnAEC = srcCN;
                  ADDING_STATE = ADD_STATE;
                  
                  //JCBCountry = clsPublicMethods.fillCombo("SELECT * FROM tblCountry",cnAEC,"Name");
                  JTFCEngName.setEditable(true);
                  JTFCFarName.setEnabled(true);
                  if(ADD_STATE==true)
                  {
                        JLPic1.setIcon(new ImageIcon("images/bNew.png"));
                        setTitle("Add Newwww City");
                        JBUpdate.setText("Update");
                        
                  }
                  else
                  {
                        
                  }
                  
                  JPanel JPContainer = new JPanel();
                  JPContainer.setLayout(null);
                  //-- Add the JLPic1
                  JLPic1.setBounds(5,5,32,32);
                  JPContainer.add(JLPic1);
                  
                  //-- Add the JLBanner
                  JLBanner.setBounds(55,5,268,48);
                  JLBanner.setFont(new Font("Dialog",Font.PLAIN,12));
                  JPContainer.add(JLBanner);
                  
                  //******************** Start adding of input field
                  //-- Add Id Input Field
                  JLCEngName.setBounds(5,50,105,20);
                  JLCEngName.setFont(new Font("Dialog",Font.PLAIN,12));
                  
                  JTFCEngName.setBounds(110,50,200,20);
                  JTFCEngName.setFont(new Font("Dialog",Font.PLAIN,12));
                  
                  JPContainer.add(JLCEngName);
                  JPContainer.add(JTFCEngName);
                  
                  //-- Add Name Input Field
                  JLCFarName.setBounds(5,72,105,20);
                  JLCFarName.setFont(new Font("Dialog",Font.PLAIN,12));
                  
                  JTFCFarName.setBounds(110,72,200,20);
                  JTFCFarName.setFont(new Font("Dialog",Font.PLAIN,12));
                  
                  JPContainer.add(JLCFarName);
                  JPContainer.add(JTFCFarName);
                  //-- Add Contact Name Input Field
                  JLCPrefix.setBounds(5,94,105,20);
                  JLCPrefix.setFont(new Font("Dialog",Font.PLAIN,12));
                  
                  JTFCPrefix.setBounds(110,94,200,20);
                  JTFCPrefix.setFont(new Font("Dialog",Font.PLAIN,12));
                  
                  JPContainer.add(JLCPrefix);
                  JPContainer.add(JTFCPrefix);
                  
                  //******************** End adding of input field
                  
                  //-- Add the JBUpdate     5,318,105,25
                  JBUpdate.setBounds(5,135,105,25);
                  JBUpdate.setFont(new Font("Dialog", Font.PLAIN, 12));
                  JBUpdate.setMnemonic(KeyEvent.VK_A);
                  JBUpdate.addActionListener(JBActionListener);
                  JBUpdate.setActionCommand("update");
                  JPContainer.add(JBUpdate);
                  
                  //-- Add the JBReset
                  JBReset.setBounds(112,135,99,25);
                  JBReset.setFont(new Font("Dialog", Font.PLAIN, 12));
                  JBReset.setMnemonic(KeyEvent.VK_R);
                  JBReset.addActionListener(JBActionListener);
                  JBReset.setActionCommand("reset");
                  JPContainer.add(JBReset);
                  
                  //-- Add the JBCancel
                  JBCancel.setBounds(212,135,99,25);
                  JBCancel.setFont(new Font("Dialog", Font.PLAIN, 12));
                  JBCancel.setMnemonic(KeyEvent.VK_C);
                  JBCancel.addActionListener(JBActionListener);
                  JBCancel.setActionCommand("cancel");
                  JPContainer.add(JBCancel);
                  
                  getContentPane().add(JPContainer);
                  setSize(325,200);
                  setResizable(false);
                  setLocation((screen.width - 325)/2,((screen.height-383)/2));
            }
            
            private void clearFields()
            {
                  JTFCEngName.setText("");
                  JTFCFarName.setText("");
                  JTFCPrefix.setText("");            
            }
            
            private boolean RequiredFieldEmpty()
            {
                  if(JTFCEngName.getText().equals(""))
                  {
                        JOptionPane.showMessageDialog(null,"Some required fields is/are empty.\nPlease check it and try again.","",JOptionPane.WARNING_MESSAGE);
                        JTFCEngName.requestFocus();
                        return true;
                  }else
                  {
                        return false;
                  }
            }
            
            private void updateCityCollection(Connection connect)
            {
                Vector cityCollect = new Vector();
                
                try
                {
                      st = connect.createStatement();
                      //"INSERT INTO CITY (CITY_ID,CITY_ENG_NAME,CITY_FARSI_NAME,PREFIX) VALUES (city_id_seq.nextval,'"+JTFCEngName.getText()+"','"+JTFCFarName.getText()+"','"+JTFCPrefix.getText()+"')");
                        //String query = "SELECT city_id, city_eng_name, city_farsi_name, prefix FROM city ORDER BY city_id";
                      String query = "INSERT INTO CITY (CITY_ID,CITY_ENG_NAME,CITY_FARSI_NAME,PREFIX) VALUES (city_id_seq.nextval,'"+JTFCEngName.getText()+"','"+JTFCFarName.getText()+"','"+JTFCPrefix.getText()+"')";
                        st.executeUpdate(query);
                        //connect.close();
                }
                catch (SQLException sqle)
                {
                      System.err.println("Can't get city collection from database : " + sqle.getMessage());
                }
          }
            
            ActionListener JBActionListener = new ActionListener()
            {
                  public void actionPerformed(ActionEvent e)
                  {
                        String srcObj = e.getActionCommand();
                        
                        if(srcObj=="update")
                        {
                              if(RequiredFieldEmpty()==false)
                              {
                                    if(ADDING_STATE == true)
                                    {
                                          updateCityCollection(OwnerForm.getDBConnection());      
                                                   // Start Display the new record
                                                   int total =0;
                                                   total = clsPublicMethods.getMaxNum("SELECT * FROM city ORDER BY city_id ASC",OwnerForm.getDBConnection(),"city_id");
                                                   
                                                   if(total != 0)
                                                   {
                                                         
                                                         System.out.print("TOTAL  1 "+total);                                      
                                                         tf.reloadRecord();
                                                         
                                                   }
                                                   else
                                                   {
                                                         //FrmCustomer.reloadRecord("SELECT * FROM tblCustomer ORDER BY CompanyName ASC"
                                                         System.out.print("TOTAL 2 "+total);

                                                         //tf.reloadRecord("SELECT * FROM city ORDER BY city_id ASC");
                                                   }
                                                   total =0;
                                                   // End Display the new record
                                                   JOptionPane.showMessageDialog(null,"New record has been successfully added.","System",JOptionPane.INFORMATION_MESSAGE);
                                                   String ObjButtons[] = {"Yes","No"};
                                                int PromptResult = JOptionPane.showOptionDialog(null,"Do you want add another record?","System",JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE,null,ObjButtons,ObjButtons[0]);
                                                
                                                if(PromptResult==0)
                                                {
                                                      clearFields();
                                                      JTFCEngName.requestFocus(true);
                                                }else
                                                {
                                                      dispose();
                                                }
                                    }
                                    else
                                    {
                                          //Update
                                    }
                              }
                        }
                        else if(srcObj=="reset")
                        {
                              clearFields();
                        }
                        else if(srcObj=="cancel")
                        {
                              dispose();
                        }
                  }
            };
            
      }
0
 
objectsCommented:
>        tf = new TreeTableInternalFrame(OwnerForm);

thats your problem.

it creates a new frame so it doesn't reference the one you want to update.
it instead updates a table in a different frame (that is not ever made visible).

you need to change that to reference the actual framr you want to update. Looks like you'll need to pass the frame in the constructor to do that.
0
 
zolfAuthor Commented:

thanks mate for finding my error.can you please also guide me in my code how can i refer to that frame.
0
 
objectsCommented:
         public Frm_add_edit_city(boolean ADD_STATE,PictMenuFrameDemo OwnerForm, TreeTableInternalFrame tableFrame)
         {
               super(OwnerForm,true);
               tf = tableFrame;
0
 
zolfAuthor Commented:
i have done what you mentioned

public Frm_add_edit_city(boolean ADD_STATE,PictMenuFrameDemo OwnerForm,TreeTableInternalFrame tableFrame)
            {
                  super(OwnerForm,true);
                  //tf = new TreeTableInternalFrame(OwnerForm);
                  tf = tableFrame;


but then the above class is called in class TreeTableInternalFrame like this,what do i put in its third argument

 private JToolBar createToolbar()
    {
          final JToolBar tb = new JToolBar();
          //.. create tool bar buttons
          JButton b1 = new JButton("Add City", testIcon);
          b1.setFocusPainted(false);
          b1.setToolTipText("Test toolbar button : icon + text");
          b1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae)
                {
                      Connection cnCus;
                      JDialog JDAdd = new Frm_add_edit_city(true,JFParentFrame,              );
                      JDAdd.setModal(false);
                  JDAdd.show();
                }
          });
          tb.add(b1);
0
 
objectsCommented:
the instance of TreeTableInternalFrame that you want to be updated.
0
 
zolfAuthor Commented:

i know,but do i need to create an instance of that class in itself.forgive me for asking so many questions because i am not very professional in java yet.
0
 
objectsCommented:
no, you need to pass the existing frame (otherwise how would it know what to update)
0
 
zolfAuthor Commented:

please give me code example like you did above.please
0
 
zolfAuthor Commented:

the class TreeInternalFrame is a JInternalFrame.in this class i have a button which when clicked opens a Jdialog.the code is this

public void actionPerformed(ActionEvent ae)
              {
                   Connection cnCus;
                   JDialog JDAdd = new Frm_add_edit_city(true,JFParentFrame,              );
                   JDAdd.setModal(false);
               JDAdd.show();
              }

now we have changed the JDialog class i.e. Frm_add_edit_city to have an instance of TreeInternalFrame

JDialog JDAdd = new Frm_add_edit_city(true,JFParentFrame,new TreeTableInternalFrame(JFParentFrame));
                      
0
 
objectsCommented:
> JDialog JDAdd = new Frm_add_edit_city(true,JFParentFrame,new TreeTableInternalFrame(JFParentFrame));

thats the same as what you are doing before. That results in you updating the newly created frame instead of the existing one.
If that code is inside the frame that you want to update then pass 'this'

JDialog JDAdd = new Frm_add_edit_city(true,JFParentFrame, TreeTableInternalFrame.this);
0
 
zolfAuthor Commented:

i made the required changes and ran the application but without showing the new row inside the table
0
 
zolfAuthor Commented:


pleaseeeee help.i need to make this work
0
 
zolfAuthor Commented:

thanks mate for all your help and patience
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 23
  • 12
  • 8
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now