设置JList索引来分隔字符串

问题描述:

我在我的程序中有一个JList,并且想知道如何将每个索引设置为String。然后使用它通过使用带有String的正则表达式来更新SQL数据库,该数组将它分成与SQL数据库列相关的三个值。设置JList索引来分隔字符串

我对如何做到这一点有一个想法,但是,我会想象有一个更有效的方法来完成这个。

int indices = JList.getLastVisibleIndex();+1; 
int stringnum = 0; 

//getLastVisibleIndex returns the integer of items I have in the JList, 
but if I have 5, the value is returned 4, etc, so I add 1. 
A more efficient way of doing this is possible, I would also imagine? 

while(stringnum<indices){ 
    JList.setSelectedIndex(1); 
    String item = JList.getSelectedIndex(); 
    //Where I use the string (I'm updating an SQL database using it) 
    remove(item); 
    //Remove is a method I have set up to remove the selected index 
    stringnum++; 
} 

我没有真正测试过上面的代码,但我会想象它会工作;我只是想,我会问在这里是否有更好的方式,任何人都知道如何解决我的问题。谢谢你的时间。 :)

所以我测试了我的代码。有效。但我仍然想知道是否有更清晰的方法来执行此操作。它也只会删除绝对可见的项目,而不是滚动窗格之外的项目。我会寻找一种方法来解决这个问题。