GeeCON Prague 2014*
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


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);
}
}
 
GeeCON Prague 2014
 
subject: dynamically adding component to JPanel