如何在Container的BorderLayout的SOUTH位置画一条水平线?
我有一个布局为 BorderLayout 的容器。我想在南位置画一条水平线,因为这个容器是重复绘制的,所以我想用水平线分隔每个容器。
这是代码:
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);
}
}
而且我还想知道如何为列表的偶数行和奇数行着色,因为我尝试过,但直到单击单元格才获得颜色。
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 delimit 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了解决方案:我派生了
BackgroundPainter
在public void Paint(Graphics g,Rectangle rect)
方法中绘制了线条 (g.drawLine( rect.getX(), rect.getY()+h-1, rect.getX()+w, rect.getY()+h-1);
)。因此,当我想在容器中画一条线时,我会编写
myContainer.getStyle().setBgPainter(new obligedClassName(myContainer));
Ok , I found the solution : I derived
BackgroundPainter
where in thepublic 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));
添加首选高度为 5 的
Label
,容器之间的背景颜色为黑色add
Label
with preferred height 5, with black bg color between containers