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


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

Re: Help in Trim and putt

From "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this>
Subject Re: Help in Trim and putt
Message-ID <48edcf02$0$15126$da0feed9@news.zen.co.uk> (permalink)
Newsgroups comp.lang.java.gui
References <48edcca6$0$15123$da0feed9@news.zen.co.uk>
Date 2011-04-27 15:49 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui

RedGrittyBrick wrote:
> 
> Sriram wrote:
>>
>> The code I tried was as follows(PLEASE NOTE since my code is
>> complicated and big I cant put in this small area,too confusing...so
>> an example here):
> 
> We don't need you whole code but we do need something that compiles and 
> runs.
> 
>>
>> String line = {"word 1", "word 2","word 3","word 4"};
> 
> You can't assign an array of Strings to a String!
> 
> String[] headings = {"word 1", "word 2","word 3","word 4"};
> 
> At this point you don't need to split it. Just use it in a JTable 
> constructor.
> 
> 
>>     System.out.println("Before trying to break "  +line);
>>        int pos=0;
>>        while((pos = line.indexOf("  "))>-1){
>>          line = line.substring(0,pos)+line.substring(pos+1);
>>     }
>>      System.out.println("After breakage\n" +line);
>>     String delims=" +"; //(How can i try this - like RGB says with
>> knowing the embedded spaces. From what I see I have one embedded space
>>                            in between Value and 3 like in the
>> example...
>>
>>    String[] headerLabels=line.split(delims);
>>     for (int i=0;i<headerLabels.length;i++){
>>      System.out.println(headerLabels[i]);
>>     }
>>      Object[][] data={{}};
>>      model=new DefaultTableModel(data,headerLabels);
>>         table=new JTable(model);
>>
>> Any ideas guys?
> 
> 1)
> String#split()
> 

2)
---------------------------------------------8<---------------------------------
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

/**
  * @author: RedGrittyBrick
  */
public class HeadingSplitter {

     public static void main(String[] args) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 new HeadingSplitter().createAndShowGUI();
             }
         });
     }


     private void createAndShowGUI() {

         Integer[][] data = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};

         String line = "word 1 word 2      word 3   word  4";
         String[] headings = {"","","",""};
         int i = 0;
         for (String item: line.split(" +")) {
             int j = i++ / 2;
             headings[j] = headings[j] + " " + item;
         }

         JTable table = new JTable(data, headings);

         JPanel p = new JPanel();
         p.add(new JScrollPane(table));

         JFrame f = new JFrame("");
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         f.add(p);
         f.pack();
         f.setLocationRelativeTo(null);
         f.setVisible(true);
     }
}
---------------------------------------------8<---------------------------------

But I don't like the value with which you initialize "line".


-- 
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 | NextPrevious in thread | Next 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