0

I have been trying for the past few hours to figure out how to add a label component to a window however with no prevail. I have created a new desktop application project in Netbeans and it comes with pre-generated code. I want to add a label to it but it just does not show?. I am unsure as to why because i am following the normal panel.add(component) convention.

Would really appreciate some help!. I pasted the full file sourecode here http://pastebin.com/qJk6bSWn .

Any ideas?

5
  • Why dont you use the designer? If you are sure about manual way, try adding simple label manually and then tracking the code of added component to see how it is added. Commented Mar 7, 2012 at 20:56
  • I want to learn how to add a component because later in my application i will need to use tables a lot. To avoid using the interface which will generate code every time i add one, i plan on creating a function so its more object orientated. But have no idea how to add components to it.. Commented Mar 7, 2012 at 20:59
  • Also I'd try changing the layout property of your mainFrame. Because if something is added after adding your label it will overlap your label by default. Commented Mar 7, 2012 at 21:01
  • I dont believe that can be it, its an empty window with no other components Commented Mar 7, 2012 at 21:03
  • Try making simple application with 1 JPanel and 1 JLabel, without aligns etc. Also try using pack(); at the end of constructor. Commented Mar 7, 2012 at 21:10

1 Answer 1

1

What layout is your JPanel using? If it's using the Netbeans GUI builder default of free design you won't be able to manually add components. You'll need to set it to some layout manager.

Parts of your gui can have the Free Design layout, but you'll need to change the layout of the components that you want to manually add to.

Sign up to request clarification or add additional context in comments.

1 Comment

I ran into the same problem a few years ago when I first worked on a GUI. I feel your pain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.