Results 1 to 4 of 4
  1. #1
    stevenfriz is offline Member
    Join Date
    Feb 2012
    Posts
    28
    Rep Power
    0

    Default 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  3. #3
    stevenfriz is offline Member
    Join Date
    Feb 2012
    Posts
    28
    Rep Power
    0

    Default 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:

    Java 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.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Question about JTabbedPanes

    Quote Originally Posted by stevenfriz View Post
    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:

    Java 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".

Similar Threads

  1. Java Question [Beginner Question]
    By joker760 in forum New To Java
    Replies: 3
    Last Post: 12-13-2011, 05:01 PM
  2. question posted by indissa: library question.
    By Fubarable in forum New To Java
    Replies: 2
    Last Post: 11-18-2011, 02:14 AM
  3. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 01:05 AM
  4. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  5. JTabbedPanes
    By Moncleared in forum New To Java
    Replies: 13
    Last Post: 09-19-2009, 08:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •