Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: JCheckBoxInJTableSelection

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Location
    negros oriental,philippines
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy JCheckBoxInJTableSelection

    hi, im new to java and im having problems with getting the selected checkbox in a jtable cell....i want to get the values of the selected one and store it into an array...could anybody help me how? tnx....

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,400
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: JCheckBoxInJTableSelection

    You're going to have to be a lot more specific. Try creating an SSCCE (that's a link) that demonstrates your problem. Don't forget the code tags.

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    repryd (December 23rd, 2010)

  4. #3
    Junior Member
    Join Date
    Dec 2010
    Location
    negros oriental,philippines
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JCheckBoxInJTableSelection

    my problem is that i want to get the checked values of the checkboxes whenever the save button is being pressed...
               empmodel.addTableModelListener(new TableModelListener()
                {
                    public void tableChanged(TableModelEvent e)
                    {
     
                        int rindex1=jTable1.getSelectedRow();
     
                        String selvalue1=jTable1.getValueAt(rindex1,1).toString();
                        String   selvalue2=getShiftIdFromShiftDesc(shifts.getSelectedItem().toString()).elementAt(0).toString();
                        String sel=jTable1.getValueAt(rindex1,0).toString();
     
                        try
                        {
                            if(sel.equals("true"))
                            {
                                new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}");
                                new ConnectDB().create("{CALL payroll._assignInsertShift('" + selvalue1 + "','" + selvalue2 + "',null,null)}");
                            }
                            else
                            {
                                new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}");
                            }
                        }
                        catch(Exception ex)
                        {
                           ex.printStackTrace();
                        }
                   }
            });
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,400
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: JCheckBoxInJTableSelection

    That is not an SSCCE, and you did not use the code tags. Without seeing an SSCCE or understanding what you mean, I can only point you to the JTable API: JTable (Java Platform SE 6)

  6. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: JCheckBoxInJTableSelection

    Hello and welcome to the forums. Please post something we can compile.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  7. #6
    Junior Member
    Join Date
    Dec 2010
    Location
    negros oriental,philippines
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JCheckBoxInJTableSelection

    empmodel.addTableModelListener(new TableModelListener()
                {
                    public void tableChanged(TableModelEvent e)
                    {
     
                        int rindex1=jTable1.getSelectedRow();
     
                        String selvalue1=jTable1.getValueAt(rindex1,1).toString();
                        String   selvalue2=getShiftIdFromShiftDesc(shifts.getSelectedItem().toString()).elementAt(0).toString();
                        String sel=jTable1.getValueAt(rindex1,0).toString();
     
                        try
                        {
                            if(sel.equals("true"))
                            {
                                new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}");
                                new ConnectDB().create("{CALL payroll._assignInsertShift('" + selvalue1 + "','" + selvalue2 + "',null,null)}");
                            }
                            else
                            {
                                new ConnectDB().create("{CALL payroll._assignShift('" + selvalue2 + "','" + selvalue1 + "')}");
                            }
                        }
                        catch(Exception ex)
                        {
                           ex.printStackTrace();
                        }
                   }
            });
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }

  8. #7
    Junior Member
    Join Date
    Dec 2010
    Location
    negros oriental,philippines
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JCheckBoxInJTableSelection

    can you show me how to store selected checkbox values into an array...?
    for example:
    in a jtable where the first column contains checkboxes in which you need to check or uncheck...
    i jst want to retrieve that unchecked or checked values being triggered....storing it into an array....
    i mean the true or false values....

  9. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,400
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: JCheckBoxInJTableSelection

    The code you provided doesn't really help us answer your question. Did you take a look at the JTable API? There are methods for getting the values stored in the JTable. You might also check out TableModel for the same types of methods.