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 7181783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:37:48+00:00 2026-05-28T17:37:48+00:00

I want to make an event which will be triggered after i make the

  • 0

I want to make an event which will be triggered after i make the selection to the JComboBox.
the problem I’m now facing is that when i added an ActionListener, it was triggered when the user clicked on the box but BEFORE he actually chose the new item, thus the action listener was activated all the time on the previous value which was selected in the box. what i want to do is simply changing the title of an JTextArea according to the selection.
I tried doing something like this:

 jBox.addActionListener(new ActionListener(){
    @Override
    public void actionPerformed(ActionEvent e) {
    String alt = GetAlgoAreaTitleByChoice();
    panel.remove(jArea);
    currentBest = setArea("",alt);
    currentBest.setBounds(50, 350, 1000, 290);
    panel.add(jArea);
     }
     });

and the method inside:

private String GetArgsAreaTitleByChoice(){
    String chi = jBox.getSelectedItem().toString();
    if(chi.equals(generalChoice)){
    return "Hello";
    }
    else if(chi.equals(algoChoice)){
    return "World";
    }
    else if(chi.equals(argsChoice)){
    return "Hello";
    }
    return null;
}

I’ve tried using the SELECTED events now like this:

public void itemStateChanged(ItemEvent e) {
JComboBox cb = (JComboBox)e.getSource();

    // Get the affected item
    String item = cb.getSelectedItem().toString();

    if (e.getStateChange() == ItemEvent.SELECTED) {
        panel.remove(jBox);
    textArea = setArea("", item);
        panel.add(jBox);
   }

but it seems to remove the area from the panel without adding it back… why is this happening?

  • 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-28T17:37:49+00:00Added an answer on May 28, 2026 at 5:37 pm

    For listening of events from JComboBox is better implements ItemListener, returns two events SELECTED/DESELECTED

    EDIT

    if you remove/add JComponent(s) on Runtime and in already visible container, then you have to call (as least code lines)

    revalidate();
    repaint();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a single event that will capture every change in the
I want to have a Status model which will be relatively static after some
I have a selector that binds a click event which will remove the popup.
I want to make a link call a Javascript function through the onclick event
I have an object with event handlers and I want to make something similar
I'm trying to creat special event for jQuery. I want to make controled delay,
I want to know if its possible writing some code which will delete an
I would like to make a custom button, that will display 3 data bound
jQuery has a really handy event binder called live() which will add events to
I want to make a user Control in WPf with same properties and events

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.