如题!!!我在一个Jframe中加了一个myJpanel类继承了Jpanel,在MyJpanel中是一个Jlist,用来显示得到的数据!!一个按钮时,负责的相应监听更行String[]数组重新传个Jlist但控制台上...
如题!!! 我在一个Jframe中加了一个myJpanel类继承了Jpanel,在MyJpanel中是一个Jlist,用来显示得到的数据!! 一个按钮时,负责的相应监听更行String[]数组重新传个Jlist 但控制台上显示新数组已经传递过去 ,但Jlist不显示刷新!! 怎么办??
setListData();方法不好使啊!!! 也不知道是不是我的逻辑错了!!! 先是JFrame用add添加MyJPanelJPanel继承JPanel,setVisible(true), 同时JFrame实例化MYJPanel;调其中的一个go()方法;
在MyJPanel 静态变量声明JList list、 JScrollPane scrollPane、String[] result 构造方法中实例list,和其他的外观 其他的类将得到的String[]传递进来 一部分代码如下 (百度字数限制,写不全)!!
public void go() {
label.setOpaque(true);
label.setForeground(color);
label.setEnabled(true);
label.setVisible(true);
add(label);
list.setListData(RESULTS);
list.setBorder(BorderFactory.createEtchedBorder());
list.setFixedCellHeight(20);
list.setFixedCellWidth(400);
list.setDragEnabled(true);
getscrollPane();
}
public void getscrollPane() {
scrollPane = new JScrollPane();
scrollPane.setViewportView(list);
add(scrollPane);
}
}
展开