Results 1 to 6 of 6

Thread: GUI problem...

  1. #1
    kureikougaiji is offline Member
    Join Date
    Nov 2007
    Posts
    15
    Rep Power
    0

    Default GUI problem...

    how can i make checkBoxes that is dependent to an input...???
    like for example, if a user types in 4, my java system will make 4 check boxes... please help... thanks..

  2. #2
    kureikougaiji is offline Member
    Join Date
    Nov 2007
    Posts
    15
    Rep Power
    0

    Default hmm...

    can somebody help me please????

  3. #3
    kureikougaiji is offline Member
    Join Date
    Nov 2007
    Posts
    15
    Rep Power
    0

    Default hayyyy...

    i need this as soon as possible... please... somebody...:)...T_T

  4. #4
    revathi17 is offline Member
    Join Date
    Aug 2007
    Posts
    26
    Rep Power
    0

    Default

    you can start from something like this:

    Java Code:
    import java.awt.BorderLayout;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    
    public class UserInput extends JPanel{
    	
    	JPanel checkBoxPanel = new JPanel();
    	public UserInput(){
    		int noOfCBReq = Integer.parseInt(
    				JOptionPane.showInputDialog("Enter the number of check boxes needed"));
    		JCheckBox[] cb = new JCheckBox[noOfCBReq];
    		for(int i=0; i<cb.length; i++){
    			JCheckBox checkBox = new JCheckBox();
    			checkBox.setText("Check box"+i);
    			checkBoxPanel.add(checkBox);
    		}
    		add(checkBoxPanel, BorderLayout.CENTER);
    	}
    	
    	public static void main(String[] args){
    		JFrame f = new JFrame("User Input test");
    		f.getContentPane().add(new UserInput());
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.pack();
    		f.setVisible(true);
    	}
    }
    Hope this helps
    -R

  5. #5
    revathi17 is offline Member
    Join Date
    Aug 2007
    Posts
    26
    Rep Power
    0

    Default

    The other way would be to add a Textfield and a JButton. Make the user enter the number of check boxes in the text field and add a ActionListener to the JButton. Create checkboxes in the actionPerformed method of the listener.
    Depends on what you want in the GUI...


    -R

  6. #6
    kureikougaiji is offline Member
    Join Date
    Nov 2007
    Posts
    15
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •