Nov 23, 2009

2d Checkbox Array Help

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > Java

2d Checkbox Array Help

martmeister
Hey guys ..
I need a start on developing a 2-Dimensional array consisting of 8X12 checkboxes.
Can someone help me get on the right path..
I need to create them in an array and then assign a name to them so show the name in a jtextfield when it is selected
Pretty much I would like some one to show me how to go about creating this and adding a handler.. I am using no layout so do I have to identify each location or just the array location to place all on the frame..

//DECLARE COMPONENT OBJECTS
private checkBox boxItems[][]


Comment/Reply (w/o sign-up)

wutske
This is the (relevant) code I used a while ago:
Declare as a global variable in your class
CODE
private JPanel checkspanel = new javax.swing.JPanel();
private JCheckBox[][] seat_checks;


If you have a function that handles the generation of all the components (windows, buttons, ...) then you have to add these lines to it
CODE
checkspanel.setLayout(new java.awt.GridLayout(8,12));
checkspanel.setBorder(javax.swing.BorderFactory.createTitledBorder("The checkboxes"));

for (int i=0;i<8;i++)   {
            for (int j=0;j<12;j++)  {
                seat_checks[i][j] = new JCheckBox("");
                seat_checks[i][j].addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(ActionEvent order_btn_evt) {
                        checkboxActionPerformed(order_btn_evt);
                }
                seat_checks[i][j].setMargin(new java.awt.Insets(3, 3, 3, 3));
                checkspanel.add(seat_checks[i][j]);
            }
        }


This will create a JPanel with the 8x12 checkbox grid. The only thing left to do is add that panel to your layout wink.gif .

I'm not 100% sure about that ActionListener, I've never used that in my application, but it might be a good start. My guess is that the checkboxActionPerformed function gets the handler for the checkbox so it can check wether the checkbox is ticked or not. Then it's just a matter of adding or removing the checkbox's name to a list (btw. if you realy want to give them a human readable name, then you'll have to create an 12x8 string array with those names wink.gif )

 

 

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for 2d, Checkbox, Array, Help
advertisement



2d Checkbox Array Help

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com