• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

change Jframe background from actionlistener class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I creates a Jframe class, a Jpanel class, and a few actionlistener classes. I can change the color of the Jframe background from the Jpanel, however, i can't do it from Jframe or actionListeners.
Untitled1.png
[Thumbnail for Untitled1.png]
Untitled2.png
[Thumbnail for Untitled2.png]
 
Fernando Stark
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Rancher
Posts: 3051
22
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I can change the color of the Jframe background from the Jpanel,





You are not changing the color of the frame. You are changing the color of the panel. The panel covers the entire frame.



You added the MenuPanel to the content pane of the frame. The panel fills the entire content pane so you see the color of the panel, not the frame.



A couple of problems with this statement:

1. Class names should start with an upper case character.
2. You should NOT be extending JFrame. There is no need to extend any class. You are writing an ActionListener. All you need to do is implement the methods of the ActionListener.



Again, you can't change the content pane because the panel cover the entire content pane. You can change the color of the panel with code like



I suggest you read the Swing tutorial on Using Top Level Containers for some Swing basics. Keep a link to the tutorial handy. It will also show you other Swing concepts, like how to use listeners.
 
Marshal
Posts: 64658
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing: why are using the same Constraints object throughout without changing any of its attributes?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!