how can I build a composite component?

I heard that Java Swing can support composite component, meaning combining several component'sfunctionalities onto one component. Does anyone knowwhat class and methods I should choose to build sucha component? Thanks for helping!
[266 byte] By [huayuli] at [2007-9-26 1:19:32]
# 1

Hi,

I use JPanels to construct composite components.

Create a subclass of JPanel, for example as follows:

public class NameField extends JPanel {

private JTextField tf;

public NameField() {

setLayout(new BorderLayout());

add(new JLabel("Name:"), BorderLayout.WEST);

add(tf = new JTextField(10), BorderLayout.EAST);

}

public String getName() {

return tf.getText();

}

}

Now use can use this NameField component wherever you like. You could make much more complicated components, of course.

Henri

HenriGerrits at 2007-6-29 0:52:09 > top of Java-index,Archived Forums,Swing...
# 2
Just use a JPanel and .add() whatever components you want to add to it. There are several LayoutManagers that you can use to control how the components are layed out.
darrelln at 2007-6-29 0:52:09 > top of Java-index,Archived Forums,Swing...
# 3
That's not what I meant. I don't just want to put several components together but also to give one component's functionality to another.
huayuli at 2007-6-29 0:52:09 > top of Java-index,Archived Forums,Swing...
# 4
It seems like you should subclass JComponent and paste in whatever characteristics for other components you want.
darrelln at 2007-6-29 0:52:09 > top of Java-index,Archived Forums,Swing...
# 5
Or give an actual example so we can say something sensible.
DrClap at 2007-6-29 0:52:09 > top of Java-index,Archived Forums,Swing...