Hi I want to know 2 things 1) Adding JTextFields to a JPanel at runtime 2) Adding JTextFields to a JScrollPane at runtime Both JPanel & JScrollPane have been added to the main GUI at compile time itself. I need to add the JTextFields to the above 2 components at runtime. Should I set the JPanel layout to null and set it's layout only at runtime with the JTextFields? I have declared JPanel & JScrollPane at the beginning of the class as follows: public static JPanel jp; public static JScrollPane jsp; I am using a lot of other files where data is constantly moving to & from them.So since I am creating the JPanel & JScrollPane in the beginning itself and adding them to other components,I am using the keyword static. PROBLEM :
I want to just add the JTextFields to the JPanel & JScrollPane at runtime.
not able to understand what exactly u r looking for,say if u want to dynamically change layout based on some condition you can setLayout at runtime else add layout manage at one time.and add the components as u desired. using null Layout is not adviceble.always use someLayouts. I don't know why u want to use static. if u are creating only one object of that class,it won't affect the GUI visibility else,as u create new panels,and try to add it to container,it will be removed from the old one add it to new one.
If you are dynamically adding components to a visible GUI, you are going to need to call invalidate() and/or validate() on the parent component after you add the new textfields. The parent component is the component that is being added to.
Also, you won't be able to add the textfields directly to a scrollpane. You'll have to add them to a panel inside the scrollpane.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.