动作监听JList并根据Jlist选择创建Jtable

发布于 2024-10-10 10:10:05 字数 397 浏览 0 评论 0原文

我有 Jlist ,其中有表列表。我希望用户从 JList 中选择表,这应该更改在 JTable 旁边创建的 JTable 中的值。但是,我得到异常“Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

我知道该异常结果是未创建对象。

如果我让程序从 JList 读取第一个表,只要我从 JList 选择不同的值并在线程 "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException 中给出异常,它就会正常工作。

我的听众很简单

table.setModel(New TableModel):

I have Jlist that have list of tables . I want the user to select table from the JList and this should change the values in the JTable that being created next to JTable. However, I get exception "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

I know this exception result of the object not being created.

If I let the program read the first Table from JList it will work fine as soon as I select different value from JList and give me Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException.

My listener is simply

table.setModel(New TableModel):

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如若梦似彩虹 2024-10-17 10:10:05

这是目录的问题,因为 JTable 从文件中读取。
如果有人感兴趣的话,这是我为听众提供的代码。 CSVReader是读取CSV文件的AbstractTableModel
我不期待答案。

 class SharedListSelectionHandler implements ListSelectionListener {
        public void valueChanged(ListSelectionEvent e) {
 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (!lsm.isSelectionEmpty()) {

CSVReader newCSV = new CSVReader((String)FileList.getSelectedValue());
               table.setModel(newCSV);


}

It was problem with directory because JTable read from files .
here is my code for the listener if any body interested. CSVReader is AbstractTableModel that read CSV file
I don't expect answer.

 class SharedListSelectionHandler implements ListSelectionListener {
        public void valueChanged(ListSelectionEvent e) {
 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (!lsm.isSelectionEmpty()) {

CSVReader newCSV = new CSVReader((String)FileList.getSelectedValue());
               table.setModel(newCSV);


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文