try{ FileInputStream fin = new FileInputStream(datafile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); while ((aLine = br.readLine()) != null) { JButton bu[] = new JButton[10]; Box box = Box.createVerticalBox(); StringTokenizer st = new StringTokenizer(aLine, "|"); while (st.hasMoreTokens()) { ImageIcon imageicon = new ImageIcon(st.nextToken()); for (int i=0; st.hasMoreTokens(); i++) { bu[i] = new JButton(st.nextToken(), imageicon); box.add(bu[i]); cp.add(box, BorderLayout.CENTER); bu[i].setActionCommand("button"+i); } } } br.close(); }catch(Exception e){ e.printStackTrace();}