Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:59:35+00:00 2026-06-01T19:59:35+00:00

I’m new to Java, I would like to know how can I get my

  • 0

I’m new to Java, I would like to know how can I get my textarea from the main class??

This is my code:

public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();

        }
    });
}



private static void createAndShowGUI() {
    frame = new JFrame("Frame");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GuiManager animator = new GuiManager();

    frame.add(animator, BorderLayout.CENTER);

    // Display the window.
    frame.pack();
    frame.setSize(800, 500);
    frame.setVisible(true);
}

and GuiManager:

public GuiManager() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

       // .............

    // Create Scrolling Text Area in Swing
    JPanel panelLabel = new JPanel(); 
    panelLabel.setLayout(new FlowLayout());     // No content pane for JPanel.
    JPanel panel = new JPanel(); 
    panel.setLayout(new FlowLayout());     // No content pane for JPanel.


    JLabel ta1Label = new JLabel("Label One", JLabel.LEFT);
    ta1Label.setAlignmentX(Component.LEFT_ALIGNMENT);

    JTextArea ta = new JTextArea("", 10, 30);
    ta.setLineWrap(true);
    JScrollPane sbrText = new JScrollPane(ta);
    sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    JLabel ta2Label = new JLabel("Label2", JLabel.RIGHT);
    ta2Label.setAlignmentX(Component.RIGHT_ALIGNMENT);

    JTextArea ta2 = new JTextArea("", 10, 30);
    ta2.setLineWrap(true);
    JScrollPane sbrText2 = new JScrollPane(ta2);
    sbrText2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    panelLabel.add(ta1Label);
    panelLabel.add(ta2Label);
    panel.add(sbrText);
    panel.add(sbrText2);



    // Put everything together.
    add(panelLabel);
    add(panel);
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

}

My goal is to redirect the output to these textarea, and for some output I need to redirect to the textarea on the left, but sometime I need to output on the textarea on the right. What would be the best solution to do that? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:59:37+00:00Added an answer on June 1, 2026 at 7:59 pm

    Everything that you want to access seems to be in GuiManager. However, you put the declaration for it in a method. This means that it becomes a local variable. Once the method is finished with it’s code, the variable is gone and cannot be accessed any longer.

    The fix? Just make it available to all the other classes.

    public static GuiManager animator = new GuiManager();
    

    Put that where you declared all your other variables for that class, and take out the one that was located in the ‘createAndShowGUI()’ method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I would like to count the length of a string with PHP. The string
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.