| | |
How to change color of a row
![]() |
•
•
Join Date: Mar 2004
Posts: 763
Reputation:
Solved Threads: 38
Create your own custom TableCellRenderer, then set the background color of whatever the component is that you're returning for rendering.
If you do this, you'll also have to control the highlighting of when the row is selected, which is easily handles in the same renderer class. The funny statement above is just an IF ELSE statement simplified. It basically says: IF row is an even number, color it blue, ELSE color white.
Java Syntax (Toggle Plain Text)
Component c = whatever your component is (rowIndex %2 == 0) ? c.setBackground(Color.blue) : c.setBackground(Color.white);
If you do this, you'll also have to control the highlighting of when the row is selected, which is easily handles in the same renderer class. The funny statement above is just an IF ELSE statement simplified. It basically says: IF row is an even number, color it blue, ELSE color white.
![]() |
Similar Threads
- Want to change color on click!? (HTML and CSS)
- Pointers (archived tutorial) (C++)
- Inserting data from one row and change one field (MySQL)
- how to change the size of Element Id's runtime in css (HTML and CSS)
- How to change the color of selected row of an HTML table without using CSS or Javascr (VB.NET)
- Format single Row in datagridview using a value in same row (C#)
- Creating nice borders the same way they have on vbulletin (Graphics and Multimedia)
- Pointers (Part II) (C)
Other Threads in the Java Forum
- Previous Thread: ClassNotFoundException with MySql and Netbeans
- Next Thread: problem in game
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





