| Author |
How can I set the tabel headers text to a certain color?
|
ben riches
Ranch Hand
Joined: Nov 08, 2002
Posts: 126
|
|
Hello All, I have this code. I keep getting this error: The method setDefaultRenderer invoked for type javax.swing.table.JTableHeader with arguments (javax.swing.table.DefaultTableCellRenderer) is not defined I don't know why I get this error so if someone could help me. and let me know how I should address my code so that the text in the JTables header is blue, it would be great. Thanks Ben {code] int j=1; String[][] data = new String[j][2]; for (int k=0; k<j; k++){ String[] row = {"",""}; data[k] = row; } String[] columnNames = {"Table Name","Column Name"}; ivjScrollPaneTable = new javax.swing.JTable(data, columnNames); javax.swing.table.DefaultTableCellRenderer headerRenderer = new javax.swing.table.DefaultTableCellRenderer(); headerRenderer.setForeground(java.awt.Color.blue); headerRenderer.setFont(headerRenderer.getFont().deriveFont(java.awt.Font.BOLD)); ivjScrollPaneTable.getTableHeader().setDefaultRenderer(headerRenderer); ivjScrollPaneTable.setName("ScrollPaneTable"); getJScrollPane1().setColumnHeaderView(ivjScrollPaneTable.getTableHeader()); getJScrollPane1().getViewport().setBackingStoreEnabled(true); ivjScrollPaneTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); ivjScrollPaneTable.setSelectionForeground(java.awt.Color.black); ivjScrollPaneTable.setForeground(java.awt.Color.black); ivjScrollPaneTable.setGridColor(java.awt.Color.black); ivjScrollPaneTable.setBounds(0, 0, 450, 400); ivjScrollPaneTable.setSelectionBackground(java.awt.Color.white); [/code]
|
 |
Jason Steele
Ranch Hand
Joined: Apr 25, 2003
Posts: 100
|
|
try: Good Luck!
|
An egg is a chicken's house!
|
 |
Polina Bee
Greenhorn
Joined: Feb 17, 2004
Posts: 6
|
|
This code works for me: int j=1; String[][] data = new String[j][2]; for (int k=0; k<j; k++){ String[] row = {"",""}; data[k] = row; String[] columnNames = {"Table Name","Column Name"}; ivjScrollPaneTable = new javax.swing.JTable(data, columnNames); ivjScrollPaneTable.getTableHeader().setForeground(java.awt.Color.magenta); ivjScrollPaneTable.setName("ScrollPaneTable"); ivjScrollPaneTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); ivjScrollPaneTable.setSelectionForeground(java.awt.Color.black); ivjScrollPaneTable.setForeground(java.awt.Color.black); ivjScrollPaneTable.setGridColor(java.awt.Color.black); ivjScrollPaneTable.setBounds(0, 0, 450, 400); ivjScrollPaneTable.setSelectionBackground(java.awt.Color.white); JScrollPane scrollPane = new JScrollPane(ivjScrollPaneTable); ivjScrollPaneTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
|
 |
ben riches
Ranch Hand
Joined: Nov 08, 2002
Posts: 126
|
|
Hello, Thanks for the replys I have got the color perfect now but not the boldness of the text. Coukld someone please give me line of code I need to change the font please, this is what I have tried. Thanks Again Ben
|
 |
Don Kiddick
Ranch Hand
Joined: Dec 12, 2002
Posts: 580
|
|
java.awt.Font.BOLD is an int so that's not going to compile. Have you tried ? D.
|
 |
ben riches
Ranch Hand
Joined: Nov 08, 2002
Posts: 126
|
|
Hello, I have tried what you suggested and I got these errors: The type named JTableHeader is not defined The variable named aTable is not defined The field named BLUE for type named java.awt.Color is not defined I don't no why I get these errors Thanks anyway for your help. Ben
|
 |
Don Kiddick
Ranch Hand
Joined: Dec 12, 2002
Posts: 580
|
|
Originally posted by ben riches: Hello, I have tried what you suggested and I got these errors: The type named JTableHeader is not defined The variable named aTable is not defined The field named BLUE for type named java.awt.Color is not defined
1. You need to import javax.swing.table.JTableHeader 2. Substitute "aTable" for whatever your JTable is called (ivjScrollPaneTable). 3. Change BLUE to Blue. Any luck ? D.
|
 |
ben riches
Ranch Hand
Joined: Nov 08, 2002
Posts: 126
|
|
Thanks alot, I have got it now. thanks again Ben
|
 |
 |
|
|
subject: How can I set the tabel headers text to a certain color?
|
|
|