我正在学习制作像Google搜索引擎这样的自动填充TextField等等。
我所做的是从数据库中检索一些值,然后在Jlist中转换,但我发现了一个错误,并且不知道该怎么做。任何人都可以对此有所了解,这是我的源代码,请查看这个..
哦,谢谢你们提前......
public class Test_swingx extends JFrame {
public Test_swingx(String title) throws HeadlessException {
JPanel pan = new JPanel();
pan.setLayout(new BorderLayout());
JTextField jtf = new JTextField(20);
try{
Statement statement=(Statement)konek.GetConnection().createStatement();
ResultSet res=statement.executeQuery("select * from test_nama");
while(res.next())
{
String[] tab={res.getString("nama")};
}
}catch (Exception e){
JOptionPane.showMessageDialog(rootPane,"Error");
}
JList list = new JList(tab); //ERROR IS HERE, NEED HELP
AutoCompleteDecorator.decorate(list, jtf, ObjectToStringConverter.DEFAULT_IMPLEMENTATION); pan.add(jtf, BorderLayout.NORTH);
pan.add(list, BorderLayout.CENTER);
setTitle(title);
setContentPane(pan);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Test_swingx tsx = new Test_swingx("TESTING");
}
});
}
}