Java Swing- Create a function to add elements to JScrollPanel
- by battousai622
I want to create a function so that i can call add JLabel's, etc inside the JScrollPanel. I am not sure what the command is in NetBeans.
I tried doing JScrollPanel - events - container - componentAdded to create the code below. But nothing shows up when i add code to that function.
private void initComponents() {
scrollPanel = new javax.swing.JScrollPane();
scrollPanel.addContainerListener(new java.awt.event.ContainerAdapter() {
public void componentAdded(java.awt.event.ContainerEvent evt) {
scrollPanelComponentAdded(evt);
}
}
private void scrollPanelComponentAdded(java.awt.event.ContainerEvent evt) {
System.out.println("main");
}
Any help would be great, thanks.