Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Coloring the Row in JTable
Roshini Sridharan
Ranch Hand
Posts: 143
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
Would like to know how to dynamically set the color of the Row in the JTable, Any idea's weblinks would be of great help.
Thanx in advance.
Regards
Roshini.S
Michael Dunn
Ranch Hand
Posts: 4632
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
simple demo
import java.awt.*; import javax.swing.*; import javax.swing.table.*; class Testing extends JFrame { public Testing() { setLocation(400,100); setDefaultCloseOperation(EXIT_ON_CLOSE); String colNames[] = {"Col 1", "Col 2","Col 3","Col 4","Col 5"}; DefaultTableModel dtm = new DefaultTableModel(null,colNames); JTable table = new JTable(dtm); table.setDefaultRenderer(Object.class, new MyRenderer()); dtm.setRowCount(30); getContentPane().add(new JScrollPane(table)); pack(); table.changeSelection(0,0,false,false); } class MyRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel lbl = ((JLabel)super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column)); //if(hasFocus)lbl.setBackground(Color.RED);//cell if(isSelected)lbl.setBackground(Color.RED);//row else lbl.setBackground(Color.WHITE); return lbl; } } public static void main (String[] args){new Testing().setVisible(true);} }
Roshini Sridharan
Ranch Hand
Posts: 143
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi,
thanx for the code. it worked well..
Regards
Roshini
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTable
JTable
JTable
JTable(!!!)
JTable
More...