Results 1 to 4 of 4
Thread: Question about JTabbedPanes
- 03-04-2012, 04:20 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 28
- Rep Power
- 0
Question about JTabbedPanes
I've just recently implemented a JTabbedPane into my textEditor I am making. I've read around a tab can't use the same components another tab is using?
Is this true? If so, is there anyway around it?
Everytime I type tabPane.addTab(); it replaces the current one. I'm just wondering if there is a work around.
-
Re: Question about JTabbedPanes
This has nothing to do with JTabbedPane and all to do with the behavior of components added to containers that have been rendered. A component can only be visualized in one container, period. To get around this, show multiple components but have them share the same model. For instance if you want several JTabbedPanes to appear to hold the same JTextArea, give the JTabbedPanes their own JTextAreas, but have all JTextAreas share the same Document which is the model for a JTextArea.
- 03-04-2012, 04:36 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 28
- Rep Power
- 0
Re: Question about JTabbedPanes
I get what you're saying. Now, when I create a new instance of JTextArea for that tab, how do I access the JTextArea outside of another method?
For example:
Say I want to tokenize that JTextArea, how do I access it from another method? I think I need to use parameters, but I haven't used them much; this will most likely make me look stupid.Java Code:public void createNewInstance(){ newJTextArea = javax.swing.JTextArea; tabPane.addTab(String, newJTextArea); }
-
Re: Question about JTabbedPanes
It doesn't make you look stupid, it suggests that you're somewhat new to Java however. And in this situation you may wish to step back from Java GUI programming and study the basics first, else you may be in for a bit of pain and frustration.
To answer your question directly -- you solve this problem by making sure that the variable that you want to access in multiple methods is declared in the class and thus is visible throughout the class. This is called having class "scope".
Similar Threads
-
Java Question [Beginner Question]
By joker760 in forum New To JavaReplies: 3Last Post: 12-13-2011, 04:01 PM -
question posted by indissa: library question.
By Fubarable in forum New To JavaReplies: 2Last Post: 11-18-2011, 01:14 AM -
Question concerning question marks and colons
By jim01 in forum New To JavaReplies: 17Last Post: 01-14-2011, 12:05 AM -
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
JTabbedPanes
By Moncleared in forum New To JavaReplies: 13Last Post: 09-19-2009, 07:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks