Search code examples
javaswingtext-formatting

How can I create a formatted text file from a series of selections from a Swing application?


I have a Java Swing application that has various screens / tabs from 1 to 8. There are series of selections and Text Inputs in each tab and in the final tab, I have a button to create a text file based on the selections the user has done. The text file should be formed in a formatted manner and that will be defined in the code. I would like to understand if there is a way to do this, other than defining each selection / control in the application to a corresponding text segment using FileWriter or anything similar.

Example:

In Screen 1:

User Selects "Radio 1" and Enters Text "Godzilla"

When in the button click, I need to create a text file suitably in this format.

Screen 1 {
Best Movie : Godzilla
}

Thank You in advance.


Solution

  • This looks exactly like JSON! Check it out here: http://www.json.org/java/

    It is formatted exactly the same way your example is! :)