Meaningless Drivel is fun!*
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 Android Security Essentials Live Lessons this week in the Android 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: 4523
    
    5

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: 3600
    
  14

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.
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..
 
Consider Paul's rocket mass heater.
 
subject: lost focus
 
Similar Threads
Spooky tabindex problem...
unable to see dynamically added component in swing
jcombobox help
Mneumonic for editable JComboBox
problem with alt - d in IE7