📄 doublerender.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -