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.
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:
Code:
public void createNewInstance(){
newJTextArea = javax.swing.JTextArea;
tabPane.addTab(String, newJTextArea);
}
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.
Re: Question about JTabbedPanes
Quote:
Originally Posted by
stevenfriz
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:
Code:
public void createNewInstance(){
newJTextArea = javax.swing.JTextArea;
tabPane.addTab(String, newJTextArea);
}
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.
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".