0

I would like to change the background of my JLabel in a JScrollPane's RowHeaderView.

JLabel jl = new JLabel("asdfasdfasdf");
jl.setForeground(Color.RED);
JScrollPane scroll = new JScrollPane();

// I Have tried
jl.setBackground(new Color(0, 0, 0, 255));
scroll.setBackground(new Color(0, 0, 0, 255));
scroll.setOpaque(true);
scroll.setVisible(true);

scroll.setRowHeaderView(jl);

However the text is red but the background remains white.

EDIT

This is a duplicate of How do I set a JLabel's background color?, however I cannot set this question as a duplicate myself as I require 250 rep.

Community
  • 1
  • 1
Moon Cheesez
  • 2,489
  • 3
  • 24
  • 38

1 Answers1

2

The default Opaque for the JLabel is false. which means not visible. use jl.setOpaque(true);

good luck.