• Post Reply Bookmark Topic Watch Topic
  • New Topic

Entering data in many tabbed JPanels and saving once

 
jimmy coyne
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I hoping some can give me some suggestions for my swing applictions.
The main JFrame s split in two , on top is a JPanel with components such as JTextField ,JTextArea ,JButton etc .The bottom of the JFrame is a JTabbedPane with multiples JPanels ( i.e. all tabbed ) each with its own components.
The user may enter in data any order they wish i.e. click on any tab enter in any info. None of the tabbed JPanels have an option to save the data.The only way info can be saved is by clicking the JButton on the top JPanel (i.e. not tabbed ).My question is , what is the cleanest / best way to collect all the data that the user has enter into each tab Jpanel so that it can be saved?
thanks in advance
jim
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would create an array in each JPanel with all the data components you want to save, then implement a saveRecord() method in each JPanel, that gets called from a saveRecord() method in your JTabbedPane, that gets called from a top-level saveRecord() method.
You would also need to write a loadRecord() method to reconstitute the data. You can probably get by with using object serialization. I think you might want to de-couple the UI from the data, so that what you are saving is just the data from your UI widgets, and not, say, and entire JTextField object.
I would first start with a simple test of saving one field on a panel, and trying to load it back in on start-up, just so you can understand the basic concept. Then you can branch out and create a "save tree" for all your nested objects.

Good Luck!

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