martmeister 0 Report post Posted April 12, 2009 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
wutske 0 Report post Posted April 13, 2009 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 itcheckspanel.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 .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 ) Share this post Link to post Share on other sites