This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reading text file using HashMap  RSS feed

 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text file with contents:

And I am loading I and II column to GUI using this code:

For III column case:


Everything works well with above code, but now I am facing problem with loading of inst#3 and inst#5 part, because they contain 2 line of string, as we don't add empty strings to ArrayList<String> inst, because by counting HashMap values, jButton1 adding SubPanels to jPanel2:

Setting up the JComboBox's and JTextFields by adding the data stored in the map:

I would like to ask how can I set the full text of inst#3 and inst#5 to jTextFields?
Any help is greatly appreciated.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tai Yo wrote:I have a text file with contents:

OK, so it sounds like you have a text file that is being used as "metadata" to build the components of a GUI.

There's nothing particularly wrong with that, but I hope you realise that there are MUCH better languages to do this than Java.

Specifically, you will probably be using reflection to create your components, which is an extension to the language, not part of it; so you will have no syntactical (or compiler) help when you write a program to parse this sort of file.

However, in terms of format, it would appear that you are now faced with a new level of "indentation" that you didn't expect.

I don't intend to go into the specifics of your format, but basically you can deal with that in two ways:
1. Proceduarally - re-write your "input" method to handle extra the level of detail by assuming that any "level 2" String may also be a List.
2. Re-write your entire input logic to treat the incoming data as a proper "tree".

I have a preference for the latter, because it's generic, and there are any number of "tree" implementations in Java on the Net (not to mention in the Java Collections Framework itself), and it'll save you from having to re-write again if you ever run into a 4th or 5th level of indentation.

Once you have a structure, how you compose it into Strings (or arrays of Strings) is up to you and your application.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!