I would like to create a JTree to use in various panels in different parts of my project, therefore, I was trying to create a JTree class to be able to import it later in another frames.
Can you please suggest how to make it workable
This is the class that contains a JScrollPane and a default JTree
public class UserJTree extends Component{
public UserJTree(){
initialize();
}
void initialize(){
JScrollPane scrollPane = new JScrollPane();
JTree tree = new JTree();
//rest of the JTree implementation
tree.setBounds(6, 6, 145, 500);
scrollPane.setViewportView(tree);
}
Component getUserTree(){
return this;
}
}
This is the panel in another class in which I wish to put my JTree
UserJTree ujt = new UserJTree();
JPanel panel_3 = new JPanel();
panel_3.setBounds(26, 51, 157, 512);
panel_3.setLayout(null);
panel_3.add(ujt.getUserTree());
newUserFrame.getContentPane().add(panel_3);