• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading text file using HashMap

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic