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

  • Home
  • SEARCH
  • 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 3965742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:30:20+00:00 2026-05-20T03:30:20+00:00

I have a handler class which implements ActionListner, FocusListner, and ItemListner. I have instantiated

  • 0

I have a handler class which implements ActionListner, FocusListner, and ItemListner. I have instantiated a gui object from a ConfrenceGUI class:

      public ConferenceGUI()
   {
      //Create a new JPanel and set its latyout mgr   
      conference = new JPanel(); 
      setLayout(new BorderLayout());  
      //create a RegPanel panel           
      regPanel = new RegPanel();
      //create new WorkshopPanel workshopPanel
      workshopPanel = new WorkshopPanel();      
      //build a buttonpanel
      buildButtonPanel();
      //Create a title panel      
      titlePanel = new JPanel(new FlowLayout());
      //create and set a font object
      titlePanel.setFont(new Font ("sansserif", Font.BOLD, 18));
      //add a label
      titlePanel.add(new Label("Select Registration Options"));      
      //Add the instantiated subpanels to the main conference gui panel
      add(titlePanel,        BorderLayout.NORTH);
      add(regPanel,          BorderLayout.WEST);
      add(workshopPanel,     BorderLayout.EAST);
      add(buttonPanel,       BorderLayout.SOUTH);
      //add an item listener to the combo box
      ConferenceHandler handler = new ConferenceHandler(this);
      regPanel.regComboBox.addItemListener(handler);
      //add a focus listener to the name field
      ConferenceHandler fhandler = new ConferenceHandler(this);
      regPanel.regTextField.addFocusListener(fhandler);
   }

I am trying to take information from the listeners (including two button listeners from a separate method in my ConferenceGUI class, which I did not include).

Here is a snipped of code from my handler:

  public void itemStateChanged(ItemEvent e)
  {
     String name = gui.regPanel.regTextField.getText(); 
     if (e.getSource() == gui.regPanel.regComboBox)
       {
          if (gui.regPanel.getRegType() == "Please select a type")
          JOptionPane.showMessageDialog(null, "Please select a registraion type",
                                        "Type Error", JOptionPane.ERROR_MESSAGE);     
          else gui.textArea.setText(name+" is a " +
                                        gui.regPanel.getRegType()+ " registration");
       }

and for the buttons:

      public void actionPerformed (ActionEvent e)
  {
    String name = gui.regPanel.regTextField.getText();
    DecimalFormat $ = new DecimalFormat("$#,##0.00");
    if (e.getSource() == gui.calcButton)//if the calculate buttton is pressed
    {
       //dislplay error box if user selects index 0
       if (gui.regPanel.getRegType() == "Please select a type")
         JOptionPane.showMessageDialog(null, "Please select a registraion type",
                                                "Type Error",JOptionPane.ERROR_MESSAGE);
       //prints to textarea if registrant will be attending keynote or not
       if (gui.regPanel.regCheckBox.isSelected())
          gui.textArea.setText("Keynote address will be attended");
            else
              gui.textArea.setText("Keynote address will not be attended");
       //prints to textarea which workshops registrant will be attending
       gui.textArea.setText(name+" is registered in these workshops:" +
                            gui.workshopPanel.getWorkshopList());
       //prints total registration fees to textarea
       gui.textArea.setText("Total charges for" + name + " are " + $.format(calcTotalCharges()));
    }
    else if (e.getSource() == gui.clearButton)//if the clear button is pressed
    {
       //clear the textarea 
       gui.textArea.setText("");  
       //reset the list
       gui.workshopPanel.workshopList.setSelectedIndex(0);
       //reset the combobox to index 0
       gui.regPanel.regComboBox.setSelectedIndex(0);
    }
  }

Problem will be obvious to all of you, but as I am just starting out, I can’t figure out why I can’t write any text into the textArea of my GUI. Apologies for the amount of code, but I wanted to try to be thorough.

Here is where the textarea comes from (which is a sperarate method contained in my ConferenceGUI class:

   private void buildButtonPanel()
   {
      //create the buttonpanel
      buttonPanel = new JPanel(new FlowLayout());
      //create the buttons
      calcButton = new JButton("Calculate Charges");
      clearButton = new JButton    ("Clear");
      //add listeners to the buttons
      ConferenceHandler ahandler = new ConferenceHandler(this);
      calcButton.addActionListener(ahandler);  
      clearButton.addActionListener(ahandler);
      //create a text area
      JTextArea textArea = new JTextArea(5,30); 
      textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
      //add everything to the buttonpanel
      buttonPanel.add(calcButton); buttonPanel.add(clearButton); buttonPanel.add(new JScrollPane(textArea));
   }

There are three other classes RegPanel, and WorkshopPanel, both of which create a couple of panels for the ConferenceGUI, which is in turn instantiated by an applet (gui).

  • 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-05-20T03:30:21+00:00Added an answer on May 20, 2026 at 3:30 am

    I’m not sure I understand your question (what doesn’t work? What do you expect and what happens?), but what’s sure is that calling setText() multiple times on a JTextArea is not a good idea : setText replaces the whole content of the text area. You should use append() to add multiple lines of text to the text area.

    EDITED :

    Now that you showed us how you built the text area, the problem is clearer : you instantiate a local variable textArea in the buildButtonPanel method, but the instance variable in your GUI points to another text area (or null).

    EDITED again :

    Your code is too complex and not complete enough to correct it, but the situation looks like this one :

    public class Bug extends JPanel {
        private JTextArea textArea = new JTextArea(); // first text area
    
        private void build()  {
            JTextArea textArea = new JTextArea(); // second text area. Inaccessible outside of this method
            this.add(new JScrollPane(textArea));
        }
    
        public void actionPerformed(ActionEvent e) {
            this.textArea.setText("foo"); // here, we modify the first text area, but it hasn't been added to the GUI, so it's invisible
        }
    }
    

    To fix it, you have to change it to this :

    public class NoBug extends JPanel {
        private JTextArea textArea = new JTextArea(); // unique text area
    
        private void build()  {
            this.add(new JScrollPane(this.textArea));
        }
    
        public void actionPerformed(ActionEvent e) {
            this.textArea.setText("foo"); // here, we modify the unique text area, which has been added to the GUI in the build() method        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have RPC service that returns an object of type GameEvent that extends from
I have the need to pass an object from jstl to a Jquery click
I have an activity object, myAct. myAct creates and calls my httpGetter object which
I have an extended dialog class that I want to show for 3 seconds
I have an onKeyDown event which is only needed for handling the Up and
I have a PHP image upload system which allows a user to upload various
I'm building a game which works as some type of a quiz. I ask
I'm attempting to re-organize my application's namespace hierarchy, so I'm using a System.Runtime.Serialization.SerializationBinder sub-class
I have a supposedly single-threaded FLTK application with a popup menu, created with Fluid.
I have a list of about 25 types found in the Microsoft .NET assembly

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.