[英]How do I make this JOptionPane load this large arrayList vertically with a JScrollBar
我知道如何用JScrollBar將此JOptionPane列表最多顯示100個項目,我知道可以做到。 我需要一些指導。 這是我的代碼
public static ArrayList<String> Matches = new ArrayList<String>();
private void itemSearch(String name) {
try{
String string;
BufferedReader reader = new BufferedReader(new FileReader("items.txt"));
while((string = reader.readLine()) != null) {
String[] args = string.split(" ");
for(int i = 0; i <= 19461; i++) {
if(args[i].contains(name)) {
itemID = Integer.parseInt(args[i-1]);
itemSearched = name;
Matches.add("Name: "+name+", ID: "+itemID+"");
System.out.println("Item name:"+args[i]+" Item ID:"+itemID+"");
}
}
if(Matches.size()<=1) {
continue;
} else {
JOptionPane.showMessageDialog(null, Matches);
}
AMItemDatabaseLabel3.setText(""+itemID+"");
}
} catch(Exception r) {
r.printStackTrace();
}
}
查閱Swing教程中有關獲取用戶輸入的部分 。
如果“可能性”的數量大於20,則將使用JList顯示值。
因此,您需要使用包含項目的Array(而不是ArrayList)。 因此,根據您當前的代碼,您需要將項目從ArrayList復制到Array。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.