Hi !
I have a JFrame which contains some textfields and buttons. imagine a situation that a user wants to fill sth in textfield, then she/he needs more textfields to be shown ! I want when the user clicks a button, more textfields will appear !
its like cc/bcc in some Email services. you enter an address in "TO" and if you need to add BCC, just click on "add bcc" and a new textfield for entering address as BCC, will appear.
Can anyone help me to write it in Java?
I have tried this but no result :

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

    jButton4.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
         jButton4.add(new JTextField("j"));
              NewJFrame a = new NewJFrame();

a.add( new JTextField("j"));

        a.validate();

a.repaint();
a.setVisible(true);

Can anyone help me or write for me a whole new code ? Thanks a lot :)

Can you make a small program that compiles, executes and tries to do what you want done?
SOmething that we can use for testing.

You're close. All you need to do is to add the new field to the existing visible JFrame - not a button, not a new frame, just the existing one.
Depending on what layout manager you are using you may also need to call pack() afterwards to let the layout manager make space for the new field.

ok so can you edit the above text for me?

why are you creating a new JFrame? there 's no need whatso ever to do so.
just instantiate a new JTextField and add that to the current JFrame.

ok so can you edit the above text for me?

No, absolutely not. This is not a "we do your homework for you" service.
We will help you to learn Java, and help you to write your own programs, but you have to put in the effort.
Try to write this yourself. Get as far as you can, then come back here for help on whatever it is that's stopping you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.