JTable with mycellrenderer stucked
Hi! I've written "TableColorRenderer extends DefaultTableCellRenderer" class to add a border to some cells
public Component getTableCellRendererComponent(JTable tblDataTable, Object value,boolean isSelected,boolean hasFocus,int row,int column){
Component ret = super.getTableCellRendererComponent(tblDataTable,value,isSelected,hasFocus,row,column);
if(colored[row]){
LinesBorder border =new LinesBorder(borderColor);
border.setThickness(new Insets(0, 0, thickness, 0));
setBorder(border);
tblDataTable.setRowHeight(row, thickness + 16);
}
return ret;
}
publicclass LinesBorderextends AbstractBorderimplements SwingConstants{
public LinesBorder(Color color){
this(color, 1);
}
public LinesBorder(Color color,int thickness){
setColor(color);
setThickness(thickness);
}
public LinesBorder(Color color, Insets insets){
setColor(color);
setThickness(insets);
}
publicvoid paintBorder(Component c, Graphics g,int x,int y,int width,int height){
Color oldColor = g.getColor();
g.setColor(northColor);
for (int i = 0; i < northThickness; i++){
g.drawLine(x, y+i, x+width-1, y+i);
}
g.setColor(southColor);
for (int i = 0; i < southThickness; i++){
g.drawLine(x, y+height-i-1, x+width-1, y+height-i-1);
}
g.setColor(eastColor);
for (int i = 0; i < westThickness; i++){
g.drawLine(x+i, y, x+i, y+height-1);
}
g.setColor(westColor);
for (int i = 0; i < eastThickness; i++){
g.drawLine(x+width-i-1, y, x+width-i-1, y+height-1);
}
g.setColor(oldColor);
}
public Insets getBorderInsets(Component c){
returnnew Insets(northThickness, westThickness, southThickness, eastThickness);
}
public Insets getBorderInsets(Component c, Insets insets){
returnnew Insets(northThickness, westThickness, southThickness, eastThickness);
}
publicboolean isBorderOpaque(){returntrue;}
publicvoid setColor(Color c){
northColor = c;
southColor = c;
eastColor = c;
westColor = c;
}
publicvoid setColor(Color c,int direction){
switch (direction){
case NORTH: northColor = c;break;
case SOUTH: southColor = c;break;
case EAST: eastColor = c;break;
case WEST: westColor = c;break;
default:
}
}
publicvoid setThickness(int n){
northThickness = n;
southThickness = n;
eastThickness = n;
westThickness = n;
}
publicvoid setThickness(Insets insets){
northThickness = insets.top;
southThickness = insets.bottom;
eastThickness = insets.right;
westThickness = insets.left;
}
publicvoid setThickness(int n,int direction){
switch (direction){
case NORTH: northThickness = n;break;
case SOUTH: southThickness = n;break;
case EAST: eastThickness = n;break;
case WEST: westThickness = n;break;
default:
}
}
publicvoid append(LinesBorder b,boolean isReplace){
if (isReplace){
northThickness = b.northThickness;
southThickness = b.southThickness;
eastThickness = b.eastThickness;
westThickness = b.westThickness;
}else{
northThickness = Math.max(northThickness ,b.northThickness);
southThickness = Math.max(southThickness ,b.southThickness);
eastThickness = Math.max(eastThickness ,b.eastThickness);
westThickness = Math.max(westThickness ,b.westThickness);
}
}
publicvoid append(Insets insets,boolean isReplace){
if (isReplace){
northThickness = insets.top;
southThickness = insets.bottom;
eastThickness = insets.right;
westThickness = insets.left;
}else{
northThickness = Math.max(northThickness ,insets.top);
southThickness = Math.max(southThickness ,insets.bottom);
eastThickness = Math.max(eastThickness ,insets.right);
westThickness = Math.max(westThickness ,insets.left);
}
}
protectedint northThickness;
protectedint southThickness;
protectedint eastThickness;
protectedint westThickness;
protected Color northColor;
protected Color southColor;
protected Color eastColor;
protected Color westColor;
}
and it seems to work great but when the JTable shows the cells with border, if i try to open a JDialog, the app becomes stucked (if i close the JDialog the app come back working)! If JTable shows the cells whitout border and i try to open same JDialog, the app works correctly. Maybe TableColorRenderer isn't the solution to paint borders in a cell? Also I'm finding a solution to overwrite the JTable's grid to avoid adding border by TableColorRenderer. Help me plese!

