• Post Reply Bookmark Topic Watch Topic
  • New Topic

Colouring a rectangle  RSS feed

 
bachir samir
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

This is my first post, I want to draw a rectangle with a blue colour, but the problem is that the method is not recognized (this thing drives me mad) can you please help me to set the colour.



Thank you in advance.
 
Paul Clapham
Sheriff
Posts: 22719
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in the API documentation for the java.lang.Color class and you will find a list of the valid constant values. And remember that Java is case-sensitive, in other words "blue" and "Blue" and "BLUE" are three different things.
 
Campbell Ritchie
Marshal
Posts: 56225
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our GUIs forum.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Look in the API documentation for the java.lang.Color class and you will find a list of the valid constant values. And remember that Java is case-sensitive, in other words "blue" and "Blue" and "BLUE" are three different things.

Color.blue and Color.BLUE are both supported. The problem is that Rectangle has no method called setBackground.
 
Campbell Ritchie
Marshal
Posts: 56225
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't you override the paintComponent() method and call the fillRectangle() or similar method of the Graphics object?
Remember to write super.paintcomponent(g); as the first statement in the paintComponent method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!