• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Output String from ArrayList in Java FX  RSS feed

 
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow coders!

I have a problem. I try to implement a method for printing all data from an ArrayList.
I want to know how to output the data from the ArrayList as Strings into a TextArea in Java FX.
The arraylist is a register of people owning bankaccounts.
I want the method to print out all the bankaccount owned by a specific person (identified by his/hers SSN)

This is the controlelr class i have so far:

Thanks alot!
/Gustav

 
Marshal
Posts: 64483
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Do you think a text area will be large enough to hold all the data you have? Doesn't it have some sort of setText() method? You might like to use a StringJoiner object (Java8+) where you are using the line end as the middle delimiter:-Sorry about the <b></b> tags; the problem will probably be corrected in the next few hours.
 
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also could create an observableList from your ArrayList and use that observableList to set cellValueproperty of a table.
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Do you think a text area will be large enough to hold all the data you have? Doesn't it have some sort of setText() method? You might like to use a StringJoiner object (Java8+) where you are using the line end as the middle delimiter:-Sorry about the <b></b> tags; the problem will probably be corrected in the next few hours.




Yes the text area will be large enough. The thing is that using a .setText() method will not be able to work since my method is defined by a ArrayList. Eclipse tells me that it cannot convert from ArrayList to String...
I write in java 1.8 so no i cannot use StringJoiner. I am thinking i might be able to use a for loop to print as many objects as the ArrayList contains. What do you think abut that? And how would you suggest a forloop of that kind looks (if you would think that it is a good idea)
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:You also could create an observableList from your ArrayList and use that observableList to set cellValueproperty of a table.



Sounds rather interesting. Could you give me an example of how that code might look if my ArrayList is called:


thanks!
 
Marshal
Posts: 5986
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The subject of Tables (TableView) is fairly involved.  I suggest you find a tutorial in the subject, start working on it, and post here if you run into problems.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basicly you have to create a table , make a column for every property of account in your controller you then asign every variable to the corresponding column.

For the example, let say I created a table in javafx with three columns, firstName, lastName and accountNumber, all three of type string and I have an object account with the same properties.
Then my controller would look something like:


But as Knute suggested a tutorial might not be a bad place to start.
Being able to use something is always nice, understanding how it works is way better...
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:The subject of Tables (TableView) is fairly involved.  I suggest you find a tutorial in the subject, start working on it, and post here if you run into problems.




Managed to make a forloop adding my ArrayList together to a String! Now looking like this:



Should work fine. But it doesnt. I have my data input method here:



And it could be the "AddAcc" method that is not working. Which makes it looks like the show method isnt working....
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the result or error that you get?
By the way, setting show to null and then initialize it as show + something (is one redundant (show += something) and two will give a unexpected result (nullsomething).
Set show to  " "...
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:What is the result or error that you get?
By the way, setting show to null and then initialize it as show + something (is one redundant (show += something) and two will give a unexpected result (nullsomething).
Set show to  " "...



I changed Null to " " as you said! But the error persits.

When I run my program this error is displayed in console:



Whenever i Press the "Show" button i get following error:




And row 56 in Person class refers to:



And moving on to my Controller class this is what is stated!
I could also show you the rest of the classes if it would help. But there are six different classes including the executable Main class.
I would be comfortable teamviewing you if you would feel like!
Would be much appriciated since I am completly stuck and this kind of issues normally dont get me stuck but now they kind os exceed my knowledge.


This is an image of the programs GUI to maybe get a better understanding



Thanks!
/Gustav
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry forgot to include the Controller class!

It is as follows


 
Knute Snortum
Marshal
Posts: 5986
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

WARNING: Loading FXML document with JavaFX API of version 10.0.1 by JavaFX runtime of version 8.0.181


This usually means you've used a version 10 Scene Builder while running Java version 8.  Get the version 8 Scene Builder here (scroll past version 10).

If version 8 Scene Builder complains about loading version 10 FXML, open the FXML file in a text editor, find the line that looks like this:
and change the 10.0.1 to 8.0.1.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gustav Lindström wrote:

I changed Null to " " as you said! But the error persits.



My remark of changing null to "" wouldn't have caused an error, it would have given you a wrong result.
Did you change your scenebuilder version like knute sugested?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm gonna try recreating your program mysef, what is the difference between show and find?
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I'm gonna try recreating your program mysef, what is the difference between show and find?



Wow thanks please do!

Show outputs all the Accounts owned by a person. (A person can own multiple accounts)
And find searches for the SSN (Social Security Number) and outputs the name in the Name textbox!
New name just sets a new name for the person!

Heres my github for the different classes as of now: https://github.com/gustavlindstroms/GustavJava/tree/Gustav/Inl%C3%A4mning6

/Gustav
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry haven't bin home to mutch today, so it took a while to respond.
How are you doing on your program for the moment?

I maded a working example of what I think it's supposed to do...
Havent really checked your git though.
Since most likely later on you will have to add a db to save the data, I maded it with maven en springBoot.

For this example I'm using a static list in the mainApp to keep track of the clients and accounts.
Only the add and search function are implemented, but it should be enough to get you going.

The MainApp:


ControllerBean (Only if you're using springBoot):


ChangeScene(SpringBoot only):


The MenuController:


AddController:


The SearchController:


I added a screenshot of the result, I hope this will get you on track.
testApp1.png
[Thumbnail for testApp1.png]
add a record
testApp2.png
[Thumbnail for testApp2.png]
search
testApp3.png
[Thumbnail for testApp3.png]
searchResult
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Sorry haven't bin home to mutch today, so it took a while to respond.
How are you doing on your program for the moment?

I maded a working example of what I think it's supposed to do...
Havent really checked your git though.
Since most likely later on you will have to add a db to save the data, I maded it with maven en springBoot.

For this example I'm using a static list in the mainApp to keep track of the clients and accounts.
Only the add and search function are implemented, but it should be enough to get you going.



Thanks mate! Really cool, going to class now but will take a look at it when I have time
 
Gustav Lindström
Greenhorn
Posts: 9
Java Oracle Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the program to work!

Edited my "New Account" button method to not change the index of the person. And added in the Accounts constructor to add it into the ArrayList.

Also, I changed my forloop in the "Show" method to do "<" instead of "<=".

So nice!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[code=java][ public static void showArrayListData() {

       ArrayList<String> names = new ArrayList<>();
       names.add("shavar");
       names.add("paul");
       names.add("meg");
       for (String name : names) {
           tf.setText("" + names.toString());

       }
   }]

i am new to site so i don't really know how to use it but is this what you mean't by displaying the names in the textfield?
demo-show-names.jpeg
[Thumbnail for demo-show-names.jpeg]
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol... @Carey Brown... Remember your comment about people needing to make their quota... Could this be what you ment...
Why post in a three week old topic after the user states ge got it to work?
 
Knute Snortum
Marshal
Posts: 5986
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, shavar litchmore!

Unfortunately, your post was not very helpful.  Here are some ways you could improve your posts in the future:

1) Make sure you UseCodeTags (that's a link) correctly.
2) Read the previous posts carefully.
3) Be wary of posting to old topics, especially ones that have been resolved.

The line just after the for loop should probably be:
I'm assuming the variable tf is a TextField, although you didn't make that clear.
 
Oh. Hi guys! Look at this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!