• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionsPane not outputting info to console

 
Jason Brody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me with a gui problem? I have a gui and when I hit the ok button after entering the information, my enhanced for loop doesn't output the ArrayList to the console. Can anyone help me?




 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off why is your ArrayList in ArrayInfo class static? When you add elements to the array list, are the elements really added? What's the size of the array list?

 
Jason Brody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is static because I want to add the first name, last name, phone, and email to the ArrayList from the CollectionsButtons Class so there are 4 textfields that I'm adding to the arraylist
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess what I tested your program and the array list got populated with empty strings BEFORE the GUI shows up. Making what ever you input irrelevant.

I suggest you put those 4 lines on ArrayInfo.stringList.add() inside the if (result == JOptionPane.OK_OPTION) block.
 
Jason Brody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked. You Da Man!
I just have one other question.
I need to add several sets of user info to the ArrayList, each time, dumping the entire list to the console but I hit ok and the windows disappears and if I hit run again the data on the console disappears
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact your posted code, the JFrame is not even visible. And I believe you want to click the "Enter info" button then the JDialog pops up. Click OK print stuff, enter some more ...

Then your JTextField lines (line 26 to 50) put into the actionPerformed() method. I mentioned JDialog rather than JOptionPane which may be better. Yet you may want to check the API to see if there is some setting to allow the pane to stay up.

About the adding data to array list... instead of adding strings consider ArrayInfo. Then override the toString() in ArrayInfo to loop through the items in each ArrayInfo.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!