1.设置表格只能选择一行
this.jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
2.设置表头不可移动
this.jTable1.getTableHeader().setReorderingAllowed(false);
3.jtable定位行
jtable.setRowSelectionInterval(80, 82);//把80到82行编程蓝色(选中)
Rectangle aRect =jTable.getCellRect(i, 2, true); //移动到指定行
jTable.scrollRectToVisible(aRect);
4.jTable每次只选中一个单元格:setCellSelectionEnabled(false)
5.获取当前日期
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//获取前一天日期:cal.add(Calendar.DAY_OF_MONTH, -1);
String mDateTime = formatter.format(cal.getTime()); //获取当前日期
6.把String类型转换成Date类型
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date dt1 = (Date) df.parse(mDateTime); //当前日期
7.比较两个日期
dt2.getTime()<=dt1.getTime()
8.设置列宽
jTable1.setAutoResizeMode(jTable1.AUTO_RESIZE_OFF); //设置表格不自动列宽
jTable1.getColumn("序号").setPreferredWidth(60);
9.替换字符串中的某一字符
str.replaceAll(",","") //把字符串中的“,”全部用“”替换调
10.分隔字符串
String s = "openagent&user=xxx&sex=yyy";
String[] sArr = s.split("&"); //把s按照"&"分割成若干个字串,并存储在字符串数组中
11.获取系统当前日期、时间
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss:SSS");//年-月-日 时-分-秒-毫秒
String mDateTime = formatter.format(cal.getTime()); //获取当前日期
12.获取本地IP、主机名
InetAddress address=InetAddress.getLocalHost();
address.getHostAddress(); //获取本机IP地址
address.getHostName(); //获取本机机器名
13.把byte[]类型转换成String
byte[] k="BBBBBB".getBytes(); //把一个String类型(BBBBBB)转换成byte[]
String a=new String (k).toString(); //把k转换成String
14.判断文件夹是否存在,如果不存在则创建
String s = System.getProperty("user.dir"); //获取当前目录
File file=new File(s+"/temp");
if((file.exists()==false)&&(file.isDirectory()==false)){
file.mkdir(); //创建目录
}
15.从剪贴板读取图片,并保存在本地
Image src=global.getImageClipboard();
int wideth = src.getWidth(null); //得到源图宽
int height = src.getHeight(null); //得到源图长
BufferedImage tag = new BufferedImage(wideth , height ,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src, 0, 0, wideth , height , null); //
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmssSSS");
String mDateTime = formatter.format(cal.getTime()); //获取当前日期
String s = System.getProperty("user.dir"); //获取当前目录
File file=new File(s+"/temp");
if((file.exists()==false)&&(file.isDirectory()==false)){
file.mkdir(); //创建目录
}
FileOutputStream out = new FileOutputStream(s+"/temp/"+mDateTime+".jpg"); //输出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag); //近JPEG编码
//System.out.print(width+"*"+height);
out.close();
16.获取当前的操作系统名称
String OS=System.getProperty("os.name"); //获取当前操作系统,Windows or Linux
17.java运行另一程序(Windows下)
Process pr=Runtime.getRuntime().exec("cmd.exe /c JAVA -jar /""+ path +"//UpdateProgram.jar/"");