DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Dynamically check every checkbox

  1. #1
    Join Date
    May 2007
    Posts
    59

    Dynamically check every checkbox

    I've created a tabbed panel in which I have 58 checkboxes. I could go about

    Code:
    If (checkbox1.IsChecked) { ... }
    But that would take forever. I'd like to know how I can go through them all. I know in .NET there is the Controls object that keeps track of all the objects on a form. Is there something I could use in java?

    Example in .NET:

    Code:
    For Each o as Object in Controls
       If o = CheckBox Then 'not exactly applicable, but you get the point
          ...
       End If
    Next

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    I don't know about java, but using javascript you could.

    Would that work for you?

  3. #3
    Join Date
    May 2007
    Posts
    59
    I am building a swing application, but sure. Maybe I can get stuff out of it that'll help me advance with my program.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663

  5. #5
    Join Date
    May 2007
    Posts
    59
    Nice, that's what I need. Thanks mate.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Then I wish I'd posted it sooner....I found it the first day you posted your question...I just wasn't sure if javascript would work for you.

    (I have posted javascript code to java questions before and gotten "yelled" at by the posting member. )

  7. #7
    Join Date
    May 2007
    Posts
    59
    Meh, it gave me an idea how to solve the problem. And for me that's the most important thing.

  8. #8
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    Did that work for you Armaron?

    I don't think it will, because there is no way you can map it to Java (directly). You could still get all components of the parent container, and iterate it and check if(obj instanceof JCheckBox). But I recommend you put the checkboxes into an array of JCheckBoxes, instead of creating a seperate variable for each checkbox. Ie,
    Code:
    JCheckBox checkBoxes[] = new JCheckBox[N];
    for(i=0; i<N; ++i) checkBoxes[i] = new JCheckBox();
    // -- place it etc
    // -- to iterate through all checkboxes:
    for(i=0; i<N; ++i)
    {
     final JCheckBox currentCheckBox = checkBoxes[i];
     // ---
    }
    In JavaScript, because you use markup to create the check boxes, to get the checkboxes in an array you have to use the code in Hack's post. But not quite so for Java, as you can directly initialize them into an array.

  9. #9
    Join Date
    May 2007
    Posts
    59
    What I did was submit the panels they were drawn in. In each panel I ran every component I could find and depending if the type (java: instanceof) was a textbox, checkbox or a radiobutton, a different value should be remembered.

    Now I've run into a nex problem. The checkboxes and textboxes are in the wrong order. The radiobuttons are fine. But if I have a checkbox I get the following:

    http://forums.devx.com/showthread.ph...198#post519198

    Any advice on that?

Similar Threads

  1. Replies: 1
    Last Post: 11-16-2007, 09:12 AM
  2. DataGrid Header in Dynamically Added Template Columns
    By David Hirschfeld in forum ASP.NET
    Replies: 0
    Last Post: 01-05-2003, 12:49 PM
  3. Check box isssue when bound to a database column
    By Narayan in forum VB Classic
    Replies: 0
    Last Post: 04-10-2001, 10:30 AM
  4. Add Check (or Checkbox) to CoolBar Button.ButtonMenu
    By Matt Petry in forum VB Classic
    Replies: 2
    Last Post: 12-05-2000, 02:27 PM
  5. Add Check (or Checkbox) to CoolBar Button.ButtonMenu
    By Matt Petry in forum VB Classic
    Replies: 0
    Last Post: 12-04-2000, 03:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center