Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel background colour  RSS feed

 
Alex Chopping
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code snippet here?
- Manish
 
Alex Chopping
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
excellent, thanks for ur help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!