Search code examples
javaswinguser-interfacejtextareajtabbedpane

how access JtextArea in a JtabbedPane in java?


I want to make a program same as notepad with tab option. I created a tab with JTabbedPane and add TextArea in that. tab created whit user when program run. how I can access to JTextArea in selected tab by user to save data and other options?


Solution

    • Write a class, extending from something like JPanel. This class will container a JTextArea (presumably within a JScrollPane)
    • Provide appropriate getters and setters and other functionality you might want to use (set/getText, load/save, whatever)

    When you need to add another tab, create an instance of this class, configure as you need. Generate a unique identifier for it (probably the same as the tab's name) and add it to a Map of some kind, keyed to the identifier.

    When you need to, using the identifier, get the instance of "editor pane".

    Some other useful methods you might need