Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4308

Re: Help in Trim and putt

From "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Subject Re: Help in Trim and putt
Message-ID <48ecbc53$0$3166$db0fefd9@news.zen.co.uk> (permalink)
Newsgroups comp.lang.java.gui
References <0374583a-371d-41c4-a134-abae3cda963e@s1g2000prg.googlegroups.com>
Date 2011-04-27 15:49 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui

Sriram wrote:
> Sriram  wrote:
>> Sabine Dinis Blochberger wrote:
>>> Sriram wrote:
>>>> 
>>>>     String line = "word1 word2             word3 word4";
>>>>     int pos=0;
>>>>     while((pos = line.indexOf("  "))>-1)
>>>>     {
>>> You check for two spaces here. This means it won't separate word1 and
>>> word2.
>>>>        line = line.substring(0,pos)+line.substring(pos+1);
>>>>      }
>>>>      System.out.println(line);
>>>>      String[] headerLabels= {line};
>>>>      Object[][] data={{}};
>>> I'm not familiar with these constructs of curly braces.
>>>>      model=new DefaultTableModel(data,headerLabels);
>>>>      table=new JTable(model);
>>
>> Thanks for your quick reply.  What I am trying to do is remove the
>> blank spaces between word2 and word3 (see string example below) and
>> make it looks like word1 word2 word3 word4 , put them in each column
>> of a JTable
>>
>> String line = "word1 word2             word3 word4";
>>
>> The String[] headerLabels must read the line output like this String[]
>> headerLabels={"word1","word2","word3","word4"} after joining them
>> together (i.e) removing the blank spaces- Hide quoted text -

I don't see where you split your "line" String into an array of String.

> 
> In addition to this, if i have something like word 1 word 2
> word 3 word 4 will the above sample code works with removing blank
> spaces and joining like this word 1 word 2 word 3 word 4 and putting
> respectively in column 1- 4 of JTable?
> 

No, that code won't work. You have headings containing embedded spaces. 
You headings are separated by spaces. You have insufficient information 
to know how to split that string into four pieces. If you know each 
heading has exactly one embedded space you can do it. For an unknown 
number of embedded spaces there is no way to decide if a space is part 
of a heading or a separator.

Are you sure you don't have (or can't arrange for) a unique separator or 
fixed number of characters per heading in the "line" variable?

-- 
RGB

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

Re: Help in Trim and putt "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
  Re: Help in Trim and putt "Sriram" <sriram@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
    Re: Help in Trim and putt "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
      Re: Help in Trim and putt "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
        Re: Help in Trim and putt "Sriram" <sriram@THRWHITE.remove-dii-this> - 2011-04-27 15:50 +0000

csiph-web