Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-17-2008, 02:17 AM
djc djc is offline
Member
 
Join Date: Jul 2008
Posts: 10
djc is on a distinguished road
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!!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-23-2008, 04:18 PM
Member
 
Join Date: Jul 2008
Posts: 31
skaspersen is on a distinguished road
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)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-23-2008, 10:22 PM
djc djc is offline
Member
 
Join Date: Jul 2008
Posts: 10
djc is on a distinguished road
Wow, I didn't even notice the option to set layout when I right clicked containers....Thanks a lot.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handle exception manually John_28 New To Java 2 06-05-2008 01:26 PM
Adding file contents to Choice component Java Tip Java Tips 0 02-07-2008 11:06 AM
Same component on all JTabbedPane java_novice AWT / Swing 4 08-06-2007 11:09 AM
Help with custom component Falcon1 AWT / Swing 8 07-21-2007 02:39 PM
Java Chart Component Jamie AWT / Swing 1 05-31-2007 08:07 PM


All times are GMT +3. The time now is 07:54 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org