File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes updating list dynamically on the frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "updating list dynamically on the frame" Watch "updating list dynamically on the frame" New topic
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: updating list dynamically on the frame