参考一下TextArea的实现~
呵呵 乱说的~

解决方案 »

  1.   

    不知道java自己有没有实现,要不自己拆分字符串算了,也不会很麻烦,估计50行左右就能搞定了。
      

  2.   

    我写了一个简单的例子,把字符串转换成你所要求的样子,你可以看一看:
    public class StringConvert {
        
        public final static int d_rows = 4;
              
        public StringConvert() {
        }
        
        public String[] convert( String s , int rows) {
            if( null == s || 0 >= rows )
                return null;
            String[] result = new String[rows];      
            try {            
                for( int i = 0; i < rows ; i ++ ) {
                    int j = 0;
                    result[i] = "";
                    while( (i + rows*j) < s.length() ) {
                        result[i] += s.charAt( i + rows*(j++) );                  
                    }
                    if( 0 == result[i].length() )
                        break; //no more chars here
                }
            }
            catch ( Exception e ) { e.printStackTrace(); }
            return result;
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {     
            String source = null;
            int rows = StringConvert.d_rows;
            if( 0 == args.length ) {
                source = "hahahahaha, this is a test";            
            }
            else if ( 1 == args.length ) {
                source = args[0];            
            }        
            else if ( 2 == args.length ) {
                source = args[0];
                try {
                    rows = (new Integer(args[1])).intValue();
                }
                catch ( Exception e ) {
                    System.out.println("variable error, illegal rows");
                    System.exit( 1 );
                }
            }
            else {
                System.out.println("Use: java ts SourceString");
                System.exit( 2 );
            }
            System.out.println("***********rows =" + rows +"*****************");
            System.out.println("***********original string*************");
            System.out.println(source);        
            System.out.println("****************************************");
            System.out.println();
            StringConvert sc = new StringConvert();
            String[] result = sc.convert( source, rows); 
            if( null == result) {
                System.out.println("Convert error");
                System.exit( 3 );
            }
            System.out.println("***********result string*************");
            for( int i = 0; i <  result.length ;i++ ) {
                if( null != result[i] )
                    System.out.println( result[i]);
            }
            System.out.println("****************************************");
        }
        
    }