JTable - Remove Alternate Row Default Color

Dear Sirs

How can I remove the alternate row default color?  I wish I could find a method for that. Unfortunately without success.
2015-06-03-151139.png
Omer-PitouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSoftware engineerCommented:
That's not the default JTable behaviour as far as I know.
Have a look at what renderer is on your table. That's probably the one that is responsible for it.
Search in your code for a call of the method 'setBackground'
0
CEHJCommented:
That's not the default JTable behaviour as far as I know.
I was wondering about that - i didn't think so either. But it's a very good one (less tiring to read) ;)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

zzynxSoftware engineerCommented:
That's not the default JTable behaviour as far as I know.
I meant with that: Your table having rows alternately colored is not the default behaviour.
0
Omer-PitouAuthor Commented:
Hi,
There is no setBackGround.
I suspect it has something to with the abstract model I am using

Curiously, when I change the Look and Feel of the entire applicaton (with the code below), that alternate row color goes away.
 try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            
            SwingUtilities.updateComponentTreeUI(this);
            //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(MenuCompta.class.getName()).log(Level.SEVERE, null, ex);
        }

Open in new window

0
zzynxSoftware engineerCommented:
Curiously, when I change the Look and Feel of the entire applicaton (with the code below), that alternate row color goes away.
OK. Then the root cause is found.
What look and was used before?
0
Omer-PitouAuthor Commented:
Before, I used the default one. I believe it should be a preset from Netbeans.
0
zzynxSoftware engineerCommented:
Before, I used the default one.
Which was?
0
Omer-PitouAuthor Commented:
Windows
0
zzynxSoftware engineerCommented:
Is your application not runnning on Windows, then?

If it is, I would think:
 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Open in new window

doesn't make any difference.
Since it just applies the system look and feel (being Windows when running on windows & kind of metal look when running on Linux)
0
Omer-PitouAuthor Commented:
Yep. That is the only choice I have now
0
zzynxSoftware engineerCommented:
Yep. That is the only choice I have now
Meaning you're running on Linux? Or on Windows?
0
Omer-PitouAuthor Commented:
I am running on Windows/
0
zzynxSoftware engineerCommented:
Then I'm surprised - but happy for you - that
 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Open in new window

works out for you.
0
CEHJCommented:
Please post the results of these two statements (where 'table' is the reference to your JTable)

System.out.println(table.getCellRenderer(0, 0).getClass());
System.out.println(table.getCellRenderer(1, 0).getClass());

Open in new window

0
Omer-PitouAuthor Commented:
These are the results
class javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer
class javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer
0
CEHJCommented:
So it looks like a 'synth' LAF thing. If you were to choose, say, metal LAF explicitly, you probably wouldn't get that alternation
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Omer-PitouAuthor Commented:
What is 'synth' LAF thing meaning?
Something I noticed too (if I am not wrong), I was uploading the table using the DefaultTableModel, there was no alternate rows. I can recheck it again.
0
zzynxSoftware engineerCommented:
What is 'synth' LAF thing meaning?
See https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/synth.html

I was uploading the table using the DefaultTableModel
I don't understand that sentence. Uploading?
0
Omer-PitouAuthor Commented:
Currently I am abstracttablemodel to create my model. Before that I was using a defaultTableModel to create the model
0
zzynxSoftware engineerCommented:
I see. Anyway, the table model you use does NOT influence the row coloring.
Coloring is a "view thing", not a "data thing".
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.