• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help displaying two labels

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to place a label in my application, but I can't get it to work. The netbeans gui builder used a grouplayout to place my other components, but because I was also using drawImage(), the components weren't placed exactly where they showed up in the builder. That was ok, but now I have a label that needs to be placed at an exact coordinate, so I'm doing it programmatically. They are the labels called fr, fl, and f2 in the code posted below. Can someone tell me or show me how to add at least one of these labels to the display? I've tried a few methods but no matter what I do nothing shows up, so I just got rid of them. I've marked where the placement code should go in DisplayCanvas by the comment /*LABEL PLACEMENT CODE GOES HERE*/.

LensSimulation: http://gsingh2011.pastebin.com/mPs5gBmd
DisplayCanvas: http://gsingh2011.pastebin.com/de4Gxp9d
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stop using NetBeans or other GIU builders at this stage.

Why are you using a window listener to close the application? Using System.exit() is drastic; if there is multi-threaded work going on, you may stop the thread when its work is incomplete and this can cause corrupted files. Also a JFrame can do its own closing, which you should find out about from the Java™ Tutorials. DISPOSE might be the best closing operation to try. You no longer need the getContentPane() method.
I can't see where you are actually adding those two, so you would have to show an SSCCE demonstrating the problem. I tried to execute the code you posted, but there is a gif dependency missing.

You have some very old-fashioned code, which looks as if it had been written to comply with AWT and JDK1.4 rather than with 21st Century Swing. I am not going even to try to read all the NetBeans code; GroupLayout is difficult to read at the best of times.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!