Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamically adding component to JPanel

 
shashi kale
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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);
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic