Results 1 to 4 of 4
Thread: Manually adding a component
- 07-17-2008, 12:17 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 10
- Rep Power
- 0
Manually adding a component
Hello everyone,
Although my last thread received no replies :( , this seems to be the only NetBeans forum that receives replies, so I will continue to seek help here :). What I'm looking to do is to add a component, say a textfield or something, manually to another component, such as a JPanel, for every entry in an array.
What I did was customize the code for a jPanel that I added, and supplemented the code with this:
for (int i = 0; i < array.length; i++) {
javax.swing.JButton blah = new javax.swing.JButton();
jPanel2.add(blah, i);
}
The add method's information box mentioned that the container that the component is added to may need to be validated after the add. I've tried also including jPanel2.validate(), but to no avail. Regardless of whether the for loop is there or not, the add method seems not to work. When I add a component using the NetBeans gui, the code that is generated is not jPanel2.add, but rather jPanel2Layout.addComponent etc. Yet there is no way to manually change that code. Frustrating!!!
- 07-23-2008, 02:18 PM #2
Member
- Join Date
- Jul 2008
- Posts
- 31
- Rep Power
- 0
You need to make sure that you have an appropriate layoutmanager installed for the JPanel. In this case the best candidate would be a BoxLayout .
If you are using BoxLayout use the Jpanel.add(Component) method.
If you are using a layoutmanager that needs constraints use the Jpanel.add(Component,Object)
- 07-23-2008, 08:22 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 10
- Rep Power
- 0
Wow, I didn't even notice the option to set layout when I right clicked containers....Thanks a lot.
- 04-01-2009, 11:51 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Handle exception manually
By John_28 in forum New To JavaReplies: 2Last Post: 06-05-2008, 11:26 AM -
Adding file contents to Choice component
By Java Tip in forum Java TipReplies: 0Last Post: 02-07-2008, 09:06 AM -
Same component on all JTabbedPane
By java_novice in forum AWT / SwingReplies: 4Last Post: 08-06-2007, 09:09 AM -
Help with custom component
By Falcon1 in forum AWT / SwingReplies: 8Last Post: 07-21-2007, 12:39 PM -
Java Chart Component
By Jamie in forum AWT / SwingReplies: 1Last Post: 05-31-2007, 06:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks