Hi everyone, i have created a panel within an scroll pane to contain some checkboxes depending on a String [] passed as parameter. The creation is easy and i show how i did it as follows, but i am not able to access to one of this checkboxes in other function which has to set selected them. I have tryed with getContentPane and similar but no achievement. I have to get access to this checkboxes to select them and get their names/ text. Any suggestion?? Thanks
param is an String[], e.g., String [] param = new String {"one","zwei","tres"} <code> Box box = Box.createVerticalBox(); JScrollPane pScroll = new JScrollPane(box, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_N EEDED); //Titel of the panel of the isotopes molecules JLabel label = new JLabel("Test events"); //It should be done only if there is any isotope of teh molecule if (parameter.length != 0){ // Create group of radio buttons ButtonGroup group = new ButtonGroup(); //create the checkboxes for the isotopes and add them to the box for (int i=0;i< parameter.length;i++) { if(parameter!= null){ JRadioButton rb = new JRadioButton(parameter); box.add(rb); group.add(rb); } //System.out.println(par ameter); } } //Add elements to the panel cPanel.add(label, BorderLayout.NORTH); //Add the scrollbar in case there were too many isotopes JScrollPane scrollPaneForListBox = new JScrollPane(box); collisionPanel.add(scrollPaneForListBox, BorderLayout.CENTER); //set minimum and maxim size cPanel.setMinimumSize(new Dimension(300,250)); cPanel.setPreferredSize(new Dimension(300,250)); cPanel.setMaximumSize(new Dimension(300,250)); // Add some breathing room... cPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); return cPanel;
//create the checkboxes for the isotopes and add them to the box <endcode>
<code> // Handle action events from all the buttons. public void actionPerformed(ActionEvent e) { String command = e.getActionCommand();
//Handle the New window button. if (ACCEPT_CONFIGURATION.equals(command)) { //activate the mexec command for (int i=0;i< isotopoPanel.getComponentCount();i++) { System.out.println(isotopoPanel.getComp onents().getClass()); } System.out.println(isotopoPanel.getComponent(1)); JCompo nent aux = (JComponent) isotopoPanel.getComponent(1); //aux.getComponents(); for (int i=0;i< aux.getComponentCount();i++) { System.out.println(aux.getComponents().getClass( )); }
System.out.println(isotopoPanel.getComponent(1)); aux = (JComponent) aux.getComponent(1); for (int i=0;i< aux.getComponentCount();i++) { System.out.println(aux.getComponents().getClass( )); }