Jump to content
xisto Community
Sign in to follow this  
martmeister

2d Checkbox Array Help

Recommended Posts

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 selectedPretty 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 OBJECTSprivate checkBox boxItems[][]

Share this post


Link to post
Share on other sites

This is the (relevant) code I used a while ago:
Declare as a global variable in your class

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
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 :o .

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 :o )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.