General discussion

Locked

Runtime

By araichura ·
i am preparing one application where i want to add jpanel to contentpane on button click.(that is actionperformed event) can you please anwser this query or solve it.

thanks
Ashish

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Runtime

by okujava In reply to Runtime

here it is:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class PanTest extends JFrame{
public PanTest(){
setBounds(200,200,200,300);
setDefaultCloseOperation(3);
getContentPane().setLayout(new FlowLayout());
JButton button = new JButton("Click me!");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(100,100));
panel.setBackground(Color.red);
getContentPane().add(panel);
validate();
}
});
getContentPane().add(button);
show();
}
public static void main(String args[]){
new PanTest();
}
}

hope it helps,

cheers

s.okujava

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums