2015-10-14 42 views
0

我如何使這個JOptionPane列表最多有100個JScrollBar的項目,我知道它可以做到。我正在尋求一點指導。 這裏是我的代碼我如何使這個JOptionPane與JScrollBar垂直加載這個大的arrayList

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(); 
       } 
      } 

回答

0

退房從Getting Users Input Swing的教程部分。

如果「可能性」的數量大於20,那麼JList將用於顯示值。

因此,您需要使用包含您的項目的數組(不是ArrayList)。因此,根據您當前的代碼,您需要將ArrayList中的項目複製到Array中。

+0

那麼我仍然需要幫助創建一個JScrollBar,儘管我非常感謝您的評論。你可以幫幫我嗎? –

+0

'那麼我仍然需要幫助創建一個JScrollBar' - 你是否首先嚐試了這個建議? – camickr

+0

所以我改變這個公共靜態ArrayList Matches = new ArrayList ();公共靜態陣列匹配=新陣列(); –