• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Setting an action for a button

 
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, so I have made a JFrame and put some JLabels in it.
I have two classes in the programm.
I have overriden the actionPerformed so I can set an action for my button. I want the button to add the oo label as soon as it is clicked but for some reason the label gets added after I click it the second time and not the first.
I wanted to know why is that so.

Thank you.




this is the class where I set the button and the label that I want to add as soon as it is clicked:

 
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a little rusty but when you change the look of something after setVisible(true) has been called then you have to invalidate it to get it to redraw. Sorry but I don't remember the exact method to call.
 
Rancher
Posts: 3248
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really sure what you are doing.

It looks to me like you are extending JButton and attempting to add a label to the button.

Instead you should be adding the label to the panel.

When adding components to a visible GUI then basic code is:

reply
    Bookmark Topic Watch Topic
  • New Topic