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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

zzynxSr. Software 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'
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) ;)
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

zzynxSr. Software 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.
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

zzynxSr. Software 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?
Omer-PitouAuthor Commented:
Before, I used the default one. I believe it should be a preset from Netbeans.
zzynxSr. Software engineerCommented:
Before, I used the default one.
Which was?
Omer-PitouAuthor Commented:
Windows
zzynxSr. Software 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)
Omer-PitouAuthor Commented:
Yep. That is the only choice I have now
zzynxSr. Software engineerCommented:
Yep. That is the only choice I have now
Meaning you're running on Linux? Or on Windows?
Omer-PitouAuthor Commented:
I am running on Windows/
zzynxSr. Software engineerCommented:
Then I'm surprised - but happy for you - that
 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

Open in new window

works out for you.
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

Omer-PitouAuthor Commented:
These are the results
class javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer
class javax.swing.plaf.synth.SynthTableUI$SynthTableCellRenderer
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

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.
zzynxSr. Software 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?
Omer-PitouAuthor Commented:
Currently I am abstracttablemodel to create my model. Before that I was using a defaultTableModel to create the model
zzynxSr. Software engineerCommented:
I see. Anyway, the table model you use does NOT influence the row coloring.
Coloring is a "view thing", not a "data thing".
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.