Question

refresh Jtable

Asked by: zolf


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());
         }  
         
    }

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-05-09 at 23:04:21ID21844669
Tags

jtable

,

refresh

Topic

Java Programming Language

Participating Experts
3
Points
500
Comments
44

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Size of JTable in JScrollPane
    Hi, Visualisation of JTable located in JScrollPane is allways same and to big for my needs. I try to chage size using JViewport 's setExtentSize but no use. How should it be done properly? Is this Layout manager issue? Here is the sample how I tried: JPanel a = new JPanel();...
  2. JTable/JScrollPane refresh problem
    This code is in an actionPerformed method, fired on button click first time through, JTable displays, but subsequent calls does not refresh the display dTable is DefaultTableModel dTable = r.displayCurrentHistory(txtMemberNumber.getText(), rentalID); JTable tabl...
  3. JTable not refreshing
    Hi I have a JTable and whenever I update it, it doesnt refresh properly. Also Initially it does not display and I have to click somewhere on the table in order for it to show up. Anyone have any ideas?
  4. jTable
    say i have a tab delimited file and i want to load it into a jtable. can someone give me the code to do it efficiently?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mayankeaglePosted on 2006-05-09 at 23:17:04ID: 16645776

Maybe you need to call fireTableModelChanged ()

 

by: zolfPosted on 2006-05-09 at 23:27:59ID: 16645822


where

 

by: mayankeaglePosted on 2006-05-09 at 23:33:02ID: 16645843

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.

 

by: zolfPosted on 2006-05-09 at 23:38:03ID: 16645869


yes i want to add row to an existing table.
what do i need to do then??
pleaseeee help

 

by: mayankeaglePosted on 2006-05-09 at 23:43:08ID: 16645883

You can add it using:

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

Use table.getModel () to get the table-model.

 

by: zolfPosted on 2006-05-09 at 23:50:55ID: 16645922


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());
                }
          }

 

by: mayankeaglePosted on 2006-05-09 at 23:53:58ID: 16645935

>>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 ;
}

 

by: zolfPosted on 2006-05-10 at 00:04:27ID: 16645979


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

 

by: mayankeaglePosted on 2006-05-10 at 00:46:12ID: 16646241

Yes, whichever class that contains the JTable.

 

by: zolfPosted on 2006-05-10 at 00:58:26ID: 16646335


can you please guide me exactly what i need to do in the code i have posted above.

 

by: mayankeaglePosted on 2006-05-10 at 01:04:57ID: 16646394

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.

 

by: zolfPosted on 2006-05-10 at 02:08:25ID: 16646857


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();
}

 

by: mayankeaglePosted on 2006-05-10 at 02:11:40ID: 16646875

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?

 

by: zolfPosted on 2006-05-10 at 02:20:41ID: 16646917


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());

  }

 

by: mayankeaglePosted on 2006-05-10 at 02:29:32ID: 16646951

Did you try fireTableModelChanged () ?

 

by: zolfPosted on 2006-05-10 at 02:32:28ID: 16646966


no,where do i add this function after revalidate() ?

 

by: mayankeaglePosted on 2006-05-10 at 02:34:27ID: 16646975

Try it before revalidate ()

 

by: zolfPosted on 2006-05-10 at 02:39:31ID: 16647000


cityTable.fireTableModelChanged();

it gives error saying not defined for JTable

 

by: zolfPosted on 2006-05-10 at 02:44:49ID: 16647024


i tried this,but the table did not refresh

model.fireTableDataChanged();

 

by: mayankeaglePosted on 2006-05-10 at 02:47:40ID: 16647044

Yeah, sorry I meant tableDataChanged.... if that doesn't work, I'm afraid I'm not sure how else it will.

 

by: zolfPosted on 2006-05-10 at 03:21:56ID: 16647209


this there no one to help me sort this problem

 

by: riaancorneliusPosted on 2006-05-10 at 03:58:47ID: 16647391

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().

 

by: objectsPosted on 2006-05-10 at 04:40:49ID: 16647599

>                                                 tf.reloadRecord();

check that tf is the frame that contains your table.

 

by: zolfPosted on 2006-05-10 at 23:26:29ID: 16655671



how can i check that,can you give me some code example

 

by: mayankeaglePosted on 2006-05-10 at 23:52:11ID: 16655760

He means where is tf declared? Is it the correct object (of the class) that has a JTable inside it?

 

by: zolfPosted on 2006-05-11 at 23:21:05ID: 16665104


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.

 

by: objectsPosted on 2006-05-12 at 00:04:43ID: 16665267

i can't see any line that assigns tf, can you post it again please.

 

by: zolfPosted on 2006-05-12 at 21:26:30ID: 16672558


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());
              }
         }

 

by: objectsPosted on 2006-05-12 at 21:31:12ID: 16672566

I didn't ask where you create the table, I am asking where you set tf
Somewhere you must have "tf = ......"

 

by: mayankeaglePosted on 2006-05-12 at 22:51:23ID: 16672716

>> if(srcObj=="update")

Should also have if ( srcObj.equals ( "update" ) )

 

by: zolfPosted on 2006-05-12 at 23:09:16ID: 16672740

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();
                        }
                  }
            };
            
      }

 

by: objectsPosted on 2006-05-12 at 23:22:34ID: 16672763

>        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.

 

by: zolfPosted on 2006-05-12 at 23:28:41ID: 16672776


thanks mate for finding my error.can you please also guide me in my code how can i refer to that frame.

 

by: objectsPosted on 2006-05-12 at 23:52:39ID: 16672813

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

 

by: zolfPosted on 2006-05-13 at 00:07:58ID: 16672867

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);

 

by: objectsPosted on 2006-05-13 at 00:09:54ID: 16672880

the instance of TreeTableInternalFrame that you want to be updated.

 

by: zolfPosted on 2006-05-13 at 00:15:31ID: 16672926


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.

 

by: objectsPosted on 2006-05-13 at 00:17:01ID: 16672954

no, you need to pass the existing frame (otherwise how would it know what to update)

 

by: zolfPosted on 2006-05-13 at 00:19:19ID: 16672979


please give me code example like you did above.please

 

by: zolfPosted on 2006-05-13 at 00:42:19ID: 16673095


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));
                      

 

by: objectsPosted on 2006-05-13 at 00:49:19ID: 16673114

> 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);

 

by: zolfPosted on 2006-05-13 at 01:12:21ID: 16673150


i made the required changes and ran the application but without showing the new row inside the table

 

by: zolfPosted on 2006-05-13 at 01:13:05ID: 16673152



pleaseeeee help.i need to make this work

 

by: zolfPosted on 2006-05-13 at 01:41:34ID: 16673201


thanks mate for all your help and patience

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...