• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JLabel background colour

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JLabel inside a JPanel and I'm trying to change the background colour of it with setBackground(Color.blue) but nothing is changing, I have the same thing with a jTextArea and that works fine, why is the JLabel not working?
Thanks!
Alex.
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code snippet here?
- Manish
 
Alex Chopping
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, this is basically how i've tried to change the background colour, with only the JTextArea colour changing, the JLabel stays the same:

public class Compare extends JPanel
{
JLabel title = new JLabel();
JTextArea text = new JTextArea();
GridBagConstraints c = new GridBagConstraints();
GridBagLayout layout = new GridBagLayout();
public Compare()
{
this.setLayout(layout);
title.setBackground(Color.blue);
text.setBackground(Color.yellow);
c.gridx = 0;
c.gridy = 0;
add(title, c);
c.gridx = 1;
add(test, c);
}
}
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just add

before this line -

This should work.
HTH,
- Manish
[ April 24, 2003: Message edited by: Manish Hatwalne ]
 
Alex Chopping
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
excellent, thanks for ur help
reply
    Bookmark Topic Watch Topic
  • New Topic