This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding JLabels to JPanel as user creates Shapes

 
Momodou Fatty
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is s program that allows a user to draw shapes by inputting the specifications(size, location, color etc). The user can select a shape and edit or delete it after creating it. I created JLabels and added MouseListeners to them. These JLabels are created when the main program runs but they are not shown yet. When a user creates/draws a shape, a label's setText is set and the label is displayed(the arrayList is updated as well). The problem is that I dont know how many shapes the user is going to create, so I dont know how many labels I need. And all these labels need MouseListeners because clicking on a label means selecting the shape associated with. So you can click on a label and you will be able to edit or delete the shape associated that label. I tried creating the labels in the actionEvent method for the shapes but they cannot be displayed if i create them there.


 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll wait for the responses in your cross-post before wading through that lot.

http://www.java-forums.org/awt-swing/16581-adding-jlabel-jframe.html
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.

Momodou,
Please read http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites.
To get the most of the Ranch you might also want to read http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch.

..and welcome to the Ranch
 
Momodou Fatty
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! Actually I posted the same question in about 5 Forums but I didn't know that was not a good idea. I didn't know I should mention that I did post it somewhere else. I registered in all these forums because I want to finish this program ASAP and i thought getting response from different Forums might be quicker and more helpful. Thanks for letting me know anyway, the reasons mentioned makes sense.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic