文件读写工具简单实现(四)--鼠标选择某行即显示某行内容

146 阅读1分钟

\

文件读取出来后,我们选择界面上人一行内容,然后把这些内容分别显示到其他输入框中

\

//添加插入符侦听器,以便侦听任何插入符的更改通知(读取光标行列数并将内容填充到需要的参数中)     
		textArea.addCaretListener(new CaretListener() {
			public void caretUpdate(CaretEvent e) {
				// TODO Auto-generated method stub
                    try {  
                        //e.getDot() 获得插入符的位置
                        int offset = e.getDot() ;  
                        int row = textArea.getLineOfOffset(offset);  
                        int column = e.getDot() - textArea.getLineStartOffset(row);  
                        // 状态栏中显示当前光标所在行号、所在列号
                        System.out.println("Line: " + (row + 1) + ", Column: " + (column+1)); 
                        String[] lineStrings = textArea.getText().split("\n");
                        System.out.println(lineStrings[row]);
                        int m = lineStrings[row].length();
                        String str1= lineStrings[row];
                        System.out.println(str1);
                        System.out.println(m);
                        ROM = row+1;//提供外部调用业务
                        sum = str1;//提供外部调用业务
                        if (m > 0) {
							System.out.println("mmmm");
							//大输入框鼠标指向某行,判断是否有GG字段,没有RF不会显示在上面
							int q = str1.indexOf("GG");
							if (q > 0) {
								System.out.println(q);
								String substrRF = str1.substring(q,q+3); 
								textField_RF.setText(substrRF);
								String substrName = str1.substring(0,q-2); 
								textField_name.setText(substrName);
								String substrNumber = str1.substring(q+4); 
								textField_number.setText(substrNumber);
							}	
						} else {
							
						}
            			
                    } catch (Exception ex) {  
                        ex.printStackTrace();  
                    }
                   
			}
			

		});


\