File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes dynamically  adding component to JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "dynamically  adding component to JPanel" Watch "dynamically  adding component to JPanel" New topic
Author

dynamically adding component to JPanel

shashi kale
Greenhorn

Joined: Sep 26, 2001
Posts: 7
HI,
i would like to add component dynamically onto jpanel.
for example there is one combo box when i choose one item then and then only second combo box will displayed with first combo

thanks in advance
shashi
kim jungil
Greenhorn

Joined: Sep 27, 2001
Posts: 27
//like this?
import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.awt.image.*;
import java.awt.event.*;
public class test6 extends JPanel {
public test6() {
setPreferredSize(new Dimension(300, 300));
JButton b = new JButton("add");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton a = new JButton("ASDFASFAFAFA");
add(a);
updateUI();
}
});
add(b);
}
// main function
public static void main(String[] args) {
JFrame f = new JFrame("asdf");
test6 b = new test6();
f.getContentPane().add(b);
f.pack();
f.setVisible(true);
}
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: dynamically adding component to JPanel