I have a Container whose Layout is BorderLayout. I want to draw a horizontal line at the SOUTH position because this Container is drawn repeatedly so I want to delimi开发者_如何学编程t each by the horizontal line.
Here is the code:
tList = new List(tModel);
tList.setListCellRenderer(new CTable(listclient));
public class CTable extends Container implements ListCellRenderer {
private Label pic = new Label("");
private Container cnt;
private Label name = new Label("");
private Label credit = new Label("");
private ligneHorizontal ligne;
private Font fontLibelle = (MenuPrincipalForm.r).getFont("FontTextFieldBold");
private Label focus = new Label("");
public CTable(Vector valeur)
{
setLayout(new BorderLayout());
addComponent(BorderLayout.WEST, pic);
cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
name.getStyle().setBgTransparency(0);
name.getStyle().setFont(fontLibelle);
credit.getStyle().setBgTransparency(0);
cnt.addComponent(name);
cnt.addComponent(credit);
ligne = new ligneHorizontal(100);
cnt.addComponent(ligne);
addComponent(BorderLayout.CENTER, cnt);
focus.getStyle().setBgTransparency(100);
}
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
{
if ("-".equalsIgnoreCase(String.valueOf(value)))
{
name.setText(" - ");
credit.setText("Encours : - Impayés : -");
pic.setIcon(null);
}
else
{
if (index%2 == 0)
this.setUIID("evenRowsCell");
else
this.setUIID("oddRowsCell");
name.setText("123456789012 - Rasolofomanana Marc");
credit.setText("Crédits : 15.000 (Ar) Impayés : 10.000 (Ar)");
pic.setIcon(null);
}
return this;
}
public Component getListFocusComponent(List list)
{
return focus;
}
}
public class ligneHorizontal extends Label {
public ligneHorizontal(int l)
{
String t = "";
do
{
t.concat(new String("-"));
}
while(t.length()<l);
this.setText(t);
this.setPreferredH(5);
this.getStyle().setBgColor(0);
}
}
And also I want to know how to coloriate even rows and odd rows of the List because I tried but the color is not get until I click on the cell.
Ok , I found the solution : I derived BackgroundPainter
where in the public void paint(Graphics g,Rectangle rect)
method I draw the line ( g.drawLine(rect.getX(), rect.getY()+h-1, rect.getX()+w, rect.getY()+h-1);
).
So when I want to draw a line in the container then I write myContainer.getStyle().setBgPainter(new derivedClassName(myContainer));
add Label
with preferred height 5, with black bg color between containers
精彩评论