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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:04:16+00:00 2026-06-01T01:04:16+00:00

In the code below, when both _uiChkTestAction and _uiChkTestItem JCheckBox are unselected, clicking bu1

  • 0

In the code below, when both _uiChkTestAction and _uiChkTestItem JCheckBox are unselected, clicking bu1 button make them both selected, but clicking bu2 button does not change _uiChkTestItem JCheckBox from being unselected to selected.

So, is there something wrong with my code ?

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class TestActionItemListener
{
public static void main(String[] _args)
{
    EventQueue.invokeLater(new Runnable(){

    public void run(){

    JFrame _fra = new JFrame("Testing");
    _fra.setSize(500, 500);
    _fra.setLayout(new FlowLayout());
    final JCheckBox _uiChkTestAction = new JCheckBox("ActionListener");
    _uiChkTestAction.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent _ev)
        {
            System.out.println("State by ActionListener: " + _uiChkTestAction.isSelected());
        }
    });

    final JCheckBox _uiChkTestItem = new JCheckBox("ItemListener");
    _uiChkTestItem.addItemListener(new ItemListener()
    {
        public void itemStateChanged(ItemEvent e)
        {
            System.out.println("State by ItemListener: " + _uiChkTestAction.isSelected());
        }
    });
    JButton bu1 = new JButton("actionlistener bu");
    bu1.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
          _uiChkTestAction.setSelected(true);
        }
     });
    JButton bu2 = new JButton("itemlistener bu");
    bu1.addActionListener(new ActionListener(){

        @Override
        public void actionPerformed(ActionEvent e) {
        _uiChkTestItem.setSelected(true);
        }
     });
    _fra.add(_uiChkTestAction);
    _fra.add(_uiChkTestItem);
    _fra.add(bu1);
    _fra.add(bu2);
    _uiChkTestAction.setSelected(true);
    _uiChkTestItem.setSelected(true);

    _fra.setVisible(true);
}}
);
}
};
  • 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-01T01:04:17+00:00Added an answer on June 1, 2026 at 1:04 am

    You add both of your listeners to the same button bu1 iso adding one to bu1 and one to bu2

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

Sidebar

Related Questions

I have written is code below, but button isn't shown because i've set FILL_PARENT
How can I make the code below work, so that both puts display 1
The code below works. But if I comment out the line Dim objRequest As
I've tried the code below on both Windows (64bit) and Linux(32bit). I was sure
Comparing two codes below,both do the same,but with slighty differences: ALTER procedure [dbo].[SP_USUARIOS_UPDATE] @usu_ds
I am pasting code below to track both eyes and overlay an image when
I have the code below to query records from a stored procedure but am
The code below works beautifully in Tomcat, but the call to getResource(...) returns null
The code below has (at least) two problems: the Copy button doesn't update the
I have the code below, if i don't use watermark it's fine but when

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.