• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NetBeans manually added component does not appear

 
Colm Dickson
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2565
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic