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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:22:54+00:00 2026-06-17T15:22:54+00:00

Please have a look at the following code import java.awt.event.*; import java.awt.*; import javax.swing.*;

  • 0

Please have a look at the following code

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;

    public class ComboIssue extends JFrame
    {
        private JRadioButton rOne, rTwo;
        private ButtonGroup group;

        private JComboBox combo;

        private JLabel label;

        public ComboIssue()
        {
            rOne = new JRadioButton("One");
            rOne.addActionListener(new ROneAction());
            rTwo = new JRadioButton("Two");
            rTwo.addActionListener(new RTwoAction());
            group = new ButtonGroup();
            group.add(rOne);
            group.add(rTwo);

            combo = new JComboBox();        
            combo.addItem("No Values");
            combo.addItemListener(new ComboAction());

            label = new JLabel("labellLabel");

            this.setLayout(new FlowLayout());
            this.add(rOne);
            this.add(rTwo);
            this.add(combo);
            this.add(label);


        this.pack();
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        }

        private class ROneAction implements ActionListener
        {
            public void actionPerformed(ActionEvent ae)
            {
                combo.removeAllItems();
                combo.addItem("One");
            }
        }

        private class RTwoAction implements ActionListener
        {
            public void actionPerformed(ActionEvent ae)
            {
                combo.removeAllItems();
                combo.addItem("Two");
            }
        }

        private class ComboAction implements ItemListener
        {
            public void itemStateChanged(ItemEvent ie)
            {
                if(ie.getStateChange() == ItemEvent.SELECTED)
                {
                    label.setText("Selected");
                }
            }
        }

        public static void main(String[]args)
        {
            new ComboIssue();
        }



}

Here what I am expecting is,

  1. Select one radio button. It will replace value in combo box.
  2. Select a value from the combo box. Now the JLabel text will be set to “Selected”

But, that is not what is happening. Instead, the JLabel text get changed as soon as you select a radio button!!! Why is this? Please help!

  • 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-17T15:22:56+00:00Added an answer on June 17, 2026 at 3:22 pm

    This is beacuse of ComboAction implements ItemListener.
    Are you not changing the value of combobox?
    When you are selecting the value of radio button?

    UPDATE:

    Well, there was a bit problem with your code.It changes the value of label, as you were having a ItemListener.So i have adopted PopupMenuListener which will shoot when the list becomes invisible.Works just fine what you want.

    code:

         import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    
    public class ComboIssue extends JFrame
    {
        private JRadioButton rOne, rTwo;
        private ButtonGroup group;
    
        private JComboBox combo;
    
        private JLabel label;
    
        public ComboIssue()
        {
            rOne = new JRadioButton("One");
            rOne.addActionListener(new ROneAction());
            rTwo = new JRadioButton("Two");
            rTwo.addActionListener(new RTwoAction());
            group = new ButtonGroup();
            group.add(rOne);
            group.add(rTwo);
    
            combo = new JComboBox();
            combo.addItem("No Values");
            combo.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox1PopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });
    
            label = new JLabel("labellLabel");
    
            this.setLayout(new FlowLayout());
            this.add(rOne);
            this.add(rTwo);
            this.add(combo);
            this.add(label);
    
    
        this.pack();
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        }
    
        private class ROneAction implements ActionListener
        {
            public void actionPerformed(ActionEvent ae)
            {
                combo.removeAllItems();
                combo.addItem("One");
            }
        }
    
        private class RTwoAction implements ActionListener
        {
            public void actionPerformed(ActionEvent ae)
            {
                combo.removeAllItems();
                combo.addItem("Two");
            }
        }
    
           private void jComboBox1PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
       label.setText("selected");
    
    }
    
        public static void main(String[]args)
        {
            new ComboIssue();
        }
    
    
    
           }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look the following code import javax.swing.*; import java.awt.event.*; import java.awt.*; public
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code import java.awt.event.*; import javax.swing.*; import java.awt.*;
Please have a look at the following code import java.awt.event.*; import javax.swing.*; import java.awt.*;
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;
Please have a look at the following code. import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.*;
Please have a look at the following code DataBaseConnector.java import java.sql.*; import javax.swing.*; public

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.