实际上,我需要一种从mysql数据库自动重新加载Jlist的方法,以防止其闪烁。
JButton btnRefresh = new JButton("Refresh");
btnRefresh.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
BindList();
}
});
btnRefresh.setBounds(199, 414, 89, 23);
getContentPane().add(btnRefresh);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@SuppressWarnings("unchecked")
public void BindList(){
Connection con;
Statement st;
ResultSet rs;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(link, Username, Password);
st = con.createStatement();
rs = st.executeQuery("SELECT * FROM groups");
listModel.clear();
while(rs.next()){
listModel.addElement("<html>"+ rs.getString(2) + " | " + rs.getString(3) + "</html>");
}
con.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
这是我的代码...我如何添加自动重新加载?