This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes lost focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "lost focus" Watch "lost focus" New topic
Author

lost focus

Prachi Vallecha
Greenhorn

Joined: Sep 16, 2010
Posts: 4
A JLabel is to be given focus and then a JButton is to be pressed to perform some changes on the JLabel...how should i proceed??
should i try giving the focuslost event on the label or the button??
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you have multiple labels, perhaps a better option might be to instead use JRadioButtons (added to a ButtonGroup),
then when the button is clicked, it changes what it has to change of the selected radiobutton.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 5003
    
    8

Prachi, is this question going the same way as your last one? That is to say, you ask, others respond, you disappear
http://www.coderanch.com/t/510489/GUI/java/Images-JLabels


luck, db
There are no new questions, but there may be new answers.
Prachi Vallecha
Greenhorn

Joined: Sep 16, 2010
Posts: 4
noo..sorry for the last one...
that was a similar issue..its resolved now...my fault
actually i have to use labels because i am using an image as icon
now i have to change the image at runtime pressing a button...but there are many labels
so focus needs to be given to the label to be changed...but there is no focus for a label right??
so is there some other way to use images other than label-icons???
or some way to give focus to the label?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4003
    
  18

What Darryl means is that, even if your problem was resolved, the ranchers here appreciate it if you let them know.

Anyway, you can listen for focus on all the labels, and have a variable somewhere in which you save which of the labels was the last one to receive focus. Then when you press the button, receive the appropriate label from the variable.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> actually i have to use labels because i am using an image as icon

several other components also display images
Prachi Vallecha
Greenhorn

Joined: Sep 16, 2010
Posts: 4
Thanks for the replies...
though i found the solution...i had completely forgotten about the mouseclicked event...
thanks everyone..
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: lost focus
 
It's not a secret anymore!