简体   繁体   中英

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?

  • 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

尝试像这样访问它:

JTextArea TextArea1= (JTextArea)jTabbedPane1.getSelectedComponent();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM