File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes NetBeans manually added component does not appear Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "NetBeans manually added component does not appear" Watch "NetBeans manually added component does not appear" New topic
Author

NetBeans manually added component does not appear

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
hi all,


When I programmatically add a component such as a list or button to a frame that I have used code to build then it will appear fine but I have an issue where the NetBeans frame that I have created and which is full of the NetBeans generated code, does not seem to respect the component that I add and thus it is not displayed.

I can for example, add a border to the panel through code which does show on screen when the project is run but a JButton or list for example will not. Why might this be?




I hope someone can shed some light thanks,

Colm
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8


Well, does your code look anything like the code generated by the IDE? Did you set any constraints?

That is why I always recommend you don't rely on the IDE to create the GUI. That way you can pick and choose which layout manger you want to use and then you will understand the code and know how to change it.

If you don't know how to use layout managers then you should read the section from the Swing tutorial on "Using Layout Managers".
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Thanks for your reply,

The code I have provided is all auto generated except for the bits I have added and highlighted concerning the button "test" and the JList. I have built guis before without using the gui builder but on this occasion I am just puzzled as to why the sections I have added to not appear. I know they would appear had I coded the gui myself as I have done this before.

Colm


pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Colm Dickson wrote:Thanks for your reply,

The code I have provided is all auto generated except for the bits I have added and highlighted concerning the button "test" and the JList. I have built guis before without using the gui builder but on this occasion I am just puzzled as to why the sections I have added to not appear. I know they would appear had I coded the gui myself as I have done this before.

As Rob explained, you can't just add things to a container that uses GroupLayout without setting the proper parameters (look how much code it takes the autogenerator to add components). So you certainly can add components to a GroupLayout-using container, but you'll have to do a LOT more work to do this (read the tutorial on GroupLayout for more on this). But THE correct answer is usually not to add components to a GroupLayout using container if it can be avoided. Using a simpler layout manager will save you a lot of time and headache. You know that you can tell NetBeans to have a container use a non-grouplayout layout.
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Thanks for that,


Now you have given me the cause of the problem then to save me some bother I think I'll code it by hand using a different layout manager.

Colm



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NetBeans manually added component does not appear