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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:00:39+00:00 2026-06-14T11:00:39+00:00

I want to ask is there a way to get information from JCheckBox without

  • 0

I want to ask is there a way to get information from JCheckBox without actionListener. In my code I scan a file of strings and each line has data which, if selected, should be added to an array in my program. Problem is that i will never know how many JCheckBoxes I will have, it depends from file.

So, my question is how to put selected strings to an array (or list) with a press of a button (ok) so i could do something else with them (in my case i need to get data from file or from hand input and put it in a red-black tree, so I will need to push selected strings to my putDataInTheTree method).

EDIT: Also, is it possible not to show those JCheckBoxes that already has been added to the program? I.E. if i choose fluids, next time I call input method fluids wont show in my panel?

Thanks in advance!

How it looks:

enter image description here

My code is so far:

public void input() {
    try {
        mainWindow.setEnabled(false);
        fromFile = new JFrame("Input from file");
        fromFile.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        fromFile.setLayout(new BorderLayout());
        fromFile.setSize(300,200);
        panelFromFile = new JPanel();
        panelFromFile.setLayout(new java.awt.GridLayout(0,1));
        JScrollPane scrollPane2 = new JScrollPane(panelFromFile); 
        scrollPane2.setMaximumSize(new Dimension(300, 180));

        FileReader File = new FileReader(data);
        BufferedReader Buffer = new BufferedReader(File); 
        while ((info = Buffer.readLine()) != null) {
            if (info != null) {
                JCheckBox check = new JCheckBox(info);
                panelFromFile.add(check);
            }
        }
        ok = new JButton("ok");
        ok.addActionListener(this);
        fromFile.add(scrollPane2, BorderLayout.CENTER);
        fromFile.add(ok, BorderLayout.SOUTH);
        fromFile.setLocationRelativeTo(null);
        fromFile.setResizable(false);
        fromFile.setVisible(true);
    }
    catch(Exception e) {
        text.append("Error in INPUT method");
        text.append(System.getProperty("line.separator"));
    }
}
  • 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-14T11:00:40+00:00Added an answer on June 14, 2026 at 11:00 am

    Add your checkboxes to a collection, and when the button is pressed, iterate through the checkboxes and get the text associated with each checked checkbox:

    private List<JCheckBox> checkBoxes = new ArrayList<JCheckBox>();
    ...
        while ((info = Buffer.readLine()) != null) {
            if (info != null) {
                JCheckBox check = new JCheckBox(info);
                panelFromFile.add(check);
                this.checkBoxes.add(check);
            }
        }
    
    ...
    public void actionPerformed(ActionEvent e) {
        List<String> infos = new ArrayList<String>();
        for (JCheckBox checkBox : checkBoxes) {
            if (checkBox.isSelected() {
                infos.add(checkBox.getText());
            }
        }
        // TODO do something with infos
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi want to ask if there is a way to do this without foreach
I just want to ask if there is any PHP/MySQL datatype that can store
I want to ask if is there any faster method how to make this
I want to ask pro developers out there that how they manage a big
want to ask user to input something but not want to wait forever. There
Just want to ask if i can use Custom Validator in client side without
I'm just wondering if there is a way to have a server push information
I want to ask you a question.I am not sure I will get any
I want to ask how other programmers are producing Dynamic SQL strings for execution
As you all know there is many file host websites, is there a way

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.