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 Murach's Java Servlets and JSP this week in the Servlets 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);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamically adding component to JPanel
 
Similar Threads
How to design a GUI which has n number of component are changing depending on the act
how can i dynamically change xsl element value
add or remove an item from drop down
how to clear the values of components on validation errors in JSF
dynamic component invalidate/validate painting issue (image examples included)