pleasure
asked on
Changing Table Header's Color
Can i change the JTable header's color? if yes, canu show me how??
thanks
thanks
ASKER
hi objetcs,
thanks for the response... do u have any example of this program? or may be do u have any links related to this matter??
thanks for the response... do u have any example of this program? or may be do u have any links related to this matter??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it's works... thanks you very much for the sample...:D
Any thing more apart from header's color?
ASKER
ya..there is little problem... when i changed the header color, the separator between column at header became invisible.. is there any wat to make it better??
yes you can put a border for the label that has been used to render the column header...want the code?
Here the Code: Just Just change the HeaderRenderer.java
HeaderRendere.java
--------------------
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.plaf.basic.*;
public class HeaderRenderer extends JLabel implements TableCellRenderer{
private Color fgColor = UIManager.getColor("TableH eader.fore ground");
private Color bgColor = UIManager.getColor("TableH eader.back ground");
private javax.swing.border.Border border = UIManager.getBorder("Table Header.cel lBorder");
public HeaderRenderer() {
setOpaque(true);
}
// Sets the foreground color for header
public void setForegroundColor(Color fgColor) {
this.fgColor=fgColor;
}
// Gets the foreground color of header
public Color getForegroundColor() {
return fgColor;
}
// Sets the background color for header
public void setBackgroundColor(Color bgColor) {
this.bgColor=bgColor;
}
// Gets the background color of header
public Color getBackgroundColor() {
return bgColor;
}
// Sets the border for header
public void setBorder(javax.swing.bord er.Border border) {
this.border = border;
}
// Gets the header border
public javax.swing.border.Border getBorder() {
return border;
}
public Component getTableCellRendererCompon ent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = this;
label.setText((value ==null) ? "" : (" "+value.toString()));
label.setForeground(getFor egroundCol or());
label.setBackground(getBac kgroundCol or());
label.setBorder(getBorder( ));
return label;
}
}
HeaderRendere.java
--------------------
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.plaf.basic.*;
public class HeaderRenderer extends JLabel implements TableCellRenderer{
private Color fgColor = UIManager.getColor("TableH
private Color bgColor = UIManager.getColor("TableH
private javax.swing.border.Border border = UIManager.getBorder("Table
public HeaderRenderer() {
setOpaque(true);
}
// Sets the foreground color for header
public void setForegroundColor(Color fgColor) {
this.fgColor=fgColor;
}
// Gets the foreground color of header
public Color getForegroundColor() {
return fgColor;
}
// Sets the background color for header
public void setBackgroundColor(Color bgColor) {
this.bgColor=bgColor;
}
// Gets the background color of header
public Color getBackgroundColor() {
return bgColor;
}
// Sets the border for header
public void setBorder(javax.swing.bord
this.border = border;
}
// Gets the header border
public javax.swing.border.Border getBorder() {
return border;
}
public Component getTableCellRendererCompon
boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = this;
label.setText((value ==null) ? "" : (" "+value.toString()));
label.setForeground(getFor
label.setBackground(getBac
label.setBorder(getBorder(
return label;
}
}
ASKER
thanks bapi..it's works great...:D
table.getColoumn(n).setHea
or
table.getTableHeader().set