JTextField iptext =new JTextField();
JButton ipconn = new JButton("Connect");
String[] str = {"1"};
JList list = new JList(str);
然后我给ipcnn添加了一个btn监听,传入了一个tablelist string数组
ipconn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
str = pt.getTables(iptext.getText());
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
然后将list添加到panel.
开始启动的时候list里显示是1,然后我在iptext中输入了ip后,点击ipconn,就没有反应,list不会刷新,求解应该怎么解决,谢谢
------解决思路----------------------
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JTextField;
public class Test extends JFrame
{
private JList list = null;
public Test() {
JTextField iptext =new JTextField();
JButton ipconn = new JButton("Connect");
String[] str = {"1"};
list = new JList(str);
ipconn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] str = {"1","2","3"};
list.setListData(str);
repaint();
}
});
this.add(list,BorderLayout.NORTH);
this.add(ipconn,BorderLayout.CENTER);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(100, 300);
}
public static void main(String[] args) {
new Test();
}
}
加个repaint即可
------解决思路----------------------
list.repaint();