public Insets getThickness() {
Insets insets = new Insets(0,0,0,0);
insets.top = 3;
insets.left = 3;
insets.bottom = 3;
insets.right = 3;
return insets;
}
class MyData implements CellBorder {
private Border border;
private Object obj;
public MyData(Object obj, Border border) {
this.obj = obj;
this.border = border;
}
public void setObject(Object obj) {
this.obj = obj;
}
public String toString() {
return obj.toString();
}
// CellBorder
public void setBorder(Border border) {
this.border = border;
}
public Border getBorder() {
return border;
}
private void testBorder(){
boolean isTop,isLeft,isBottom,isRight;
int[] columns = jTable1.getSelectedColumns();
int[] rows = jTable1.getSelectedRows();
Insets insets = getThickness();
int rowMax = rows.length;
int columnMax = columns.length;
for (int i=0;i<rowMax;i++) {
int row = rows[i];
isTop = (i == 0 )? true: false;
isBottom = (i == rowMax-1)? true: false;
for (int j=0;j<columnMax;j++) {
int column = columns[j];
isLeft = (j == 0 )? true: false;
isRight = (j == columnMax-1)? true: false;
// Geht alle Felder durch
// System.out.println(column);
// System.out.println(row);
MyData myData = (MyData)jTable1.getValueAt(row, column);
if (myData == null) {
myData = new MyData("", new LinesBorder(color,0));
}
LinesBorder border = (LinesBorder)myData.getBorder();
Insets tmp = new Insets(0,0,0,0);
if (isTop) tmp.top = Math.max(tmp.top ,insets.top);
if (isLeft) tmp.left = Math.max(tmp.left ,insets.left);
if (isBottom) tmp.bottom = Math.max(tmp.bottom ,insets.bottom);
if (isRight) tmp.right = Math.max(tmp.right ,insets.right);
border.append(tmp, true);
myData.setBorder(border);
jTable1.setValueAt(myData, row, column);
}
}
jTable1.clearSelection();
jTable1.revalidate();
jTable1.repaint();
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fmea;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* @version 1.0 03/09/99
*/
public class LinesBorder extends AbstractBorder implements SwingConstants {
protected int northThickness;
protected int southThickness;
protected int eastThickness;
protected int westThickness;
protected Color northColor;
protected Color southColor;
protected Color eastColor;
protected Color westColor;
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);
}
public void 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) {
return new Insets(northThickness, westThickness, southThickness, eastThickness);
}
public Insets getBorderInsets(Component c, Insets insets) {
return new Insets(northThickness, westThickness, southThickness, eastThickness);
}
public boolean isBorderOpaque() { return true; }
public void setColor(Color c) {
northColor = c;
southColor = c;
eastColor = c;
westColor = c;
}
public void 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:
}
}
public void setThickness(int n) {
northThickness = n;
southThickness = n;
eastThickness = n;
westThickness = n;
}
public void setThickness(Insets insets) {
northThickness = insets.top;
southThickness = insets.bottom;
eastThickness = insets.right;
westThickness = insets.left;
}
public void 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:
}
}
public void 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);
}
}
public void 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);
}
}
}