Topic: 请教jtable里的字段标题怎样对齐

  Print this page

1.请教jtable里的字段标题怎样对齐 Copy to clipboard
Posted by: Raistlin
Posted on: 2004-07-09 22:49

如何设置居中,左对齐,右对齐等?谢谢!

2.Re:请教jtable里的字段标题怎样对齐 [Re: Raistlin] Copy to clipboard
Posted by: bujinwang
Posted on: 2004-07-20 03:13

使用以下的 renderer和合适的format 以及你喜欢的 allignment.

Make sure to set it on the coloms where it's required with something like this:

yourTable.setDefaultRenderer(Integer.class, new TableCellRendererSimple(integerFormat, JTextField.TRAILING))

Where integerFormat is for instance a DecimalFormat instance.


/**
* TableCellRenderer.
*
* @author Rene Peters
* @version 1.0 15-dec-2003
*/
public class TableCellRendererSimple extends DefaultTableCellRenderer {

Format format = null;

public TableCellRendererSimple(Format format, int allignment) {
super();
this.format = format;
this.setHorizontalAlignment(allignment);
}

public void setValue(Object value) {
if (format == null) {
setText((value == null) ? "" : value.toString());
} else {
setText((value == null) ? "" : format.format(value));
}
}
}


Change the JTextField.TRAILING into LEFT, RIGHT, CENTER for your own requirement.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923