wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes Adding JLabels to JPanel as user creates Shapes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding JLabels to JPanel as user creates Shapes" Watch "Adding JLabels to JPanel as user creates Shapes" New topic

Adding JLabels to JPanel as user creates Shapes

Momodou Fatty

Joined: Mar 03, 2009
Posts: 2
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

Joined: Jun 09, 2003
Posts: 4632
I'll wait for the responses in your cross-post before wading through that lot.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10768

Thanks Michael.

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

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Momodou Fatty

Joined: Mar 03, 2009
Posts: 2
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Adding JLabels to JPanel as user creates Shapes
It's not a secret anymore!