| Author |
updating list dynamically on the frame
|
Rajesh Chandra
Ranch Hand
Joined: Jun 13, 2005
Posts: 55
|
|
Hi everybody, I have 2 buttons in a panel on a frame which triggers event.one saves the data from a textfield to databse and the other get the data from database and populate into the list which i have added to the frame.When i click the view button it paints a list with data from database.And if i save (click the save button),the database updates but if i click view again the list doesnt update withnew values(without closing the frame).Can anyone spot the error? Thanks in advance. regs-Rajesh This is the code snippet:- pt is panel ,view is button pt.view.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand()=="view"){ viewPhoneBook(); add(lst, BorderLayout.EAST); po=lst.getLocationOnScreen(); // Point po=lst.getLocationOnScreen(); System.out.println("location "+po); validate(); } } } ); public void viewPhoneBook(){ // static int i=0; r1=new String[35]; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc dbc:acodbc","",""); stmt=con.createStatement(); rs=stmt.executeQuery("SELECT* from PHONEDIARY"); while(rs.next()) { // Label ld=new Label(rs.getString(1)+" "+rs.getInt(2)); r1[i]=rs.getString(1); System.out.println(i+" "); System.out.println("r[i] in while"+r1[i]); // add(ld); i++;//=i; // return i; // gridbag.setConstraints(ld, constraints); } }catch(Exception e){} lst = new List(i, true); System.out.println("i after while"+PhoneBook1.i); System.out.println("r[2] after while"+r1[2]); for(int j=0;j<i;j++){ lst.add(r1[j]); } i=0; //pt.add(lst); validate(); }
|
 |
cat cater
Ranch Hand
Joined: Jun 06, 2005
Posts: 39
|
|
I think there has a error. "add(lst, BorderLayout.EAST);" new code : JMainFrame.this.add(lst, BorderLayout.EAST); you try again.
|
 |
cat cater
Ranch Hand
Joined: Jun 06, 2005
Posts: 39
|
|
|
"JMainFrame" is the current classname.
|
 |
cat cater
Ranch Hand
Joined: Jun 06, 2005
Posts: 39
|
|
|
new code : JMainFrame.this.pt.add(lst, BorderLayout.EAST)
|
 |
 |
|
|
subject: updating list dynamically on the frame
|
|
|