Ivan Delgado Ivan Delgado - 1 year ago 89
Java Question

Populate a JComboBox with an ArrayList from a different class

I'm currently stuck in this part of a class project... I need to create an ArrayList from a text file; text file has account numbers that need to be populated in a JComboBox. This is what I have so far... only the first account number populates missing the rest not sure what my mistake is

// AccountUtility class that reads file and creates ArrayList named test

public class AccountUtility {

ArrayList<String> test = new ArrayList<String>();
String[] number;
String columns[], accountNumber, customerName, openDate, balance;
int size;

public AccountUtility(){

BufferedReader in = null;
try{ // assume products.txt already exists
in = new BufferedReader(new FileReader("accounts.txt"));
String line = in.readLine();
while(line != null) {
columns = line.split("<>");
accountNumber = columns[0];
customerName = columns[1];
openDate = columns[2];
balance = columns[3];

line = in.readLine();
catch(IOException ioe)

public ArrayList <String> getAccountNumbers( ){

ArrayList <String> test = new ArrayList<String>();

return test;

//class with JComboBox (GUI)

public class BankAccountApp extends javax.swing.JFrame {

public BankAccountApp() {


AccountUtility gc = new AccountUtility();

for( String numbers : gc.getAccountNumbers()){

Answer Source

I would have thought that what you want is

while(line != null)  {
    columns = line.split("<>");
    accountNumber = columns[0];


public ArrayList getAccountNumbers( ){
   return test;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download