Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Caps Action problem  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've this swing aplication that has a label inside a jPanel; i want this label to get enabled if caps lock is on
some code i'm using:


anyhow this doesnt perform as i expected: if i have capslock on and the run my aplication, she opens with the label disabled - the opposite i intended; only after turning caps off and on again the label gets enabled

can anyone please help me in order to have the label enabled the moment i run my aplication if caps is on?

thanks in advance
 
Rob Camick
Ranch Hand
Posts: 2754
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//invoked inside aplication constructor


Don't know what that means. You don't invoke an Action from within a constructor.

All you need to add to your constructor is:



If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that solved my problem; ty, Rob

BTW: a week ago i posted a question about controling font size when printing; could you perhaps give it a look, please?
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
miguel lisboa wrote:ty, Rob

Please use real words.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
//invoked inside aplication constructor


Don't know what that means. You don't invoke an Action from within a constructor.

All you need to add to your constructor is:



If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

i'm resurrectting this topic because i still have duplicated code
my goal:
i want my application (app) to react to the CapsLock key in this way: if caps key is on i want my app's label to display "CAPS" when it opens up; also, if now i turn off caps, i want my app to stop displaying that string; in the same way, if capsLock is off before i start my app i want it to display nothing, and, at the moment i turn capsLock on i want the app to react accordingly, displaying "CAPS" string inside the label
my current code, as it is now, performs exactly in the way i want

Rob's recomendation works in the sense it reacts to caps, but only once
i tried adding the action at several places but with no effect
the only way (i've find out till now) to achieve my goal is as i show in the code below, though it goes against Rob's recomendation

can someone please help me optimizing the code?

thanks in advance

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!