doublerender.java
来自「参考了JAVA方面MIS系统开发的书籍做的一个 电力收费的系统,包里面是可以直」· Java 代码 · 共 16 行
JAVA
16 行
import java.text.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;class DoubleRender extends JLabel implements TableCellRenderer{
NumberFormat nf = NumberFormat.getNumberInstance();
DecimalFormat df= (DecimalFormat)nf; //和读数的精确到小数点后3位 public DoubleRender(){
super();
setOpaque(true); df.applyPattern("##########0.00");
this.setHorizontalAlignment(SwingConstants.RIGHT); setHorizontalTextPosition(SwingConstants.RIGHT);
}
public Component getTableCellRendererComponent(
JTable table, Object str, boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected){ this.setForeground(table.getSelectionForeground());
this.setBackground(table.getSelectionBackground());
}
else{ this.setForeground(table.getForeground());
this.setBackground(table.getBackground()); }
Object value=table.getModel().getValueAt(row,column); String display="";
if(value!=null) display=df.format(value);
this.setText(display);
return this;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?