Print array to table

I need to print two arrays in a table, i.e. each array represents another column in the table.
I currently have this which outputs the results of each array but not in table format:
String[] FN = (String[])setFN.toArray(new String[setFN.size()]);
               String[] SerialArray = (String[])setSerial.toArray(new String[setSerial.size()]);
               StringBuilder FNbuilder = new StringBuilder(FN.length);
               for (int i=0;i<FN.length;FNbuilder.append(FN[i++])) FNbuilder.append("\n");
               for (int i=0;i<SerialArray.length;FNbuilder.append(SerialArray[i++])) FNbuilder.append("\n");
               JOptionPane.showMessageDialog(null, FNbuilder.toString(), "Printing results", JOptionPane.INFORMATION_MESSAGE);I hoped it would be as easy as this, but its not! -
JTable jTable1 = new JTable (FN);
String [] columnNames = {"Serial Number", "Friendly Name"};
Object [][]data = {
     {SerialArray},{FN}
JTable jTable1 = new JTable (data, columnNames);Any advice would be greatly appreciated.
Thanks!

Those sort of parallel arrays are generally a bad idea. I call that code smell "object denial".
Anyway, you have several options.
1. Copy the data over to a Object[][] where the data is orgainized by row, not column.
2. Define an object that holds a serial number and a friendly name, call it Product, or whatever it should be. Instead of having separate arrays have a single:
List<Product>
subclass AbstractTableModel to draw its data from a List<Product>. Done!

Similar Messages

  • Convert byte array to table of int

    [http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
    I'm pretty new with PL/SQL.
    I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
    The code converts byte array to table of int.
    The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
    The TSQL code is:
    CREATE FUNCTION dbo.GetTableVarchar(@Data image)
    RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
    Value Varchar(8000))
    AS
    BEGIN
    --First Test the data is of type Varchar.
    IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
    --Loop thru the list inserting each
    -- item into the variable table.
    DECLARE @Ptr int, @Length int,
    @VarcharLength smallint, @Value Varchar(8000)
    SELECT @Length = DataLength(@Data), @Ptr = 2
    WHILE(@Ptr<@Length)
    BEGIN
    --The first 2 bytes of each item is the length of the
    --varchar, a negative number designates a null value.
    SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
    SET @Ptr = @Ptr + 2
    IF(@VarcharLength<0)
    SET @Value = NULL
    ELSE
    BEGIN
    SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
    SET @Ptr = @Ptr + @VarcharLength
    END
    INSERT INTO @DataTable (Value) VALUES(@Value)
    END
    RETURN
    END
    It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
    The C# code is:
    public byte[] Convert2Bytes(int[] list)
    if (list == null || list.Length == 0)
    return new byte[0];
    byte[] data = new byte[list.Length * 4];
    int k = 0;
    for (int i = 0; i < list.Length; i++)
    byte[] intBytes = BitConverter.GetBytes(list);
    for (int j = intBytes.Length - 1; j >= 0; j--)
    data[k++] = intBytes[j];
    return data;
    I tryied to convert the TSQL code to PL/SQL and thats what I've got:
    FUNCTION GetTableInt(p_Data blob)
    RETURN t_array --t_array is table of int
    AS
    l_Ptr number;
    l_Length number;
    l_ID number;
    l_data t_array;
    BEGIN
         l_Length := dbms_lob.getlength(p_Data);
    l_Ptr := 1;
         WHILE(l_Ptr<=l_Length)
         loop
              l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
              IF(l_ID<-2147483646)THEN
                   IF(l_ID=-2147483648)THEN
                        l_ID := NULL;
                   ELSE
                        l_Ptr := l_Ptr + 4;
                        l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
                   END IF;
                   END IF;
    l_data(l_data.count) := l_ID;
              l_Ptr := l_Ptr + 4;
         END loop;
         RETURN l_data;
    END GetTableInt;
    This isn't work.
    This is the error:
    Error report:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    06502. 00000 - "PL/SQL: numeric or value error%s"
    I think the problem is in this line:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    but I don't know how to fix that.
    Thanks,
    MTs.

    I'd found the solution.
    I need to write:
    l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
    instead of:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works.

  • How can I print a html table and preview it?

    Hi there!
    Please help me.
    I spent a lot of time to find how to print a html table and preview it.
    I tried use code of the book http://www.manning.com/sbe/ Chapter 22. But this book consists only code for rtf and they change size of JtextPane before printing.
    I have found the bellow code;
    http://forum.java.sun.com/thread.jsp?thread=120578&forum=57&message=316116 But I problems with printing.
    I also found this code; http://forum.java.sun.com/thread.jsp?forum=31&thread=146439
    But there is no code,so i don't understand.
    Can u help me?
    Thanks my friends.

    There is the comp.lang.javacript newsgroup for one:
    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&group=comp.lang.javascript
    Here are a couple of more candidates I found from google in about two minutes:
    http://www.jguru.com/forums/home.jsp?topic=JavaScript
    http://www.jsworkshop.com/bb/viewforum.php?f=1&sid=524b20160ca47c0ab786214e2003f1d1
    http://javascript.internet.com/forum/
    I am sure there are many more. :)

  • Array or Table of Records or...what is best for my scenario?

    I have been given task to trap last 5 action taken on a form application by user. This would be used where user gets a FRM or ORA error, dump last 5 steps to a table in the database along with error. Trapping FRM or ORA error is easy; I am wondering what & how should I note last 5 steps ( like, what page, what block & what form the user was clicking/entering data etc) when error occurred. I am planning to use when-mouse-click or some other triggers to capture the data; but at every action if I try inserting one record & deleting one record from the database table ( last one knocked out), there is going to be a lot of I/O & that table is going to be too hot. I am trying to avoid that unwanted I/O & keep those 5 steps info somewhere in forms till user gets a error. And, when he/she gets error, he/she can dump those 5 steps info along with error messages/number in a error table.
    My question is: what do I use? Array or Table of records..or something else. I have never used any of these & thought to discuss this before going deep into implementation.
    Any suggestion would be appreciated.
    Thanks.

    You could use a table of records or a record group. They both achieve similar results but with very different syntax. I am not sure if there is any difference in performance.
    Record groups are good for certain things like lists populated from the database because built-ins are provided for manipulating them. If you are going to do the manipulation programatically, I personally find the syntax for tables of records less cumbersome than record groups. Learning the syntax for tables of records is also likely to be more universally useful to you as they have various uses such as passing data between procedures.
    In your situation the table of records needs to exist throughout the forms session rather than just during the execution of a single pl/sql block. The way to do that is create a program unit which is a package header without a body. Declare the table in there and it can be used throughout the form.
    However, if you only ever want to keep 5 records, it would probably be easier just to have 5 ordinary items in a control block on the null canvas (or global variables). When you want to record your new action just do:
    :item5 := :item4;
    :item4 := :item3;
    :item3 := :item2;
    :item2 := :item1;
    :item1 := :new_stuff;
    You could even construct the above in a loop using
    copy(name_in('item'||i),'item'i+i)
    but with only 5 items to manipulate, is it worth the bother ?
    Whatever method you decide to use, you are not going to get anything simpler than 5 little assignment statements.

  • HOW TO MAKE THE CONTENT OF THE TABLE PRINT IN A TABLE CONTROL SCREEN?

    Can any one tell me how to make the content of the table control print in a table control screen!!?
    Please help!!
    I have to make the contents of a table in the table control screen print ? any idea
    Regards,
    Vj

    Please refer to Demo Program,
    DEMO_DYNPRO_TABCONT_LOOP
    Its very clear.
    Shreekant

  • Printing array help please!

    Hi, I have a problem with printing arrays in a certain order. Let me descbribe it, by the way I'm using Java version 1.3 if that helps.
    ok, what I need to do is print out on a single line all the strings found on the command line that end in .java and then I need to print out all the strings found on the command line that end in .class. So say I type on the command line a.java b.class c.java d.class. Then it would print out a.java c.java b.class d.class.
    any help would be appreciated!

    here it goes the complete code:
    * running example: java a.class b.java c.class d.class h.java
    public class Nickal01
         static public void main(String[] args)
              String classes = "";
              for(int i=0; i<args.length; i++)
                   if(args.endsWith(".class"))
                        classes += args[i] + " ";
                   else
                        System.out.print(args[i]+" ");
              System.out.println(classes);

  • Waveform Array in Table

    How can I display content of a waveform array in a table? Within my solution I'm only able to show content in one cell. I'd like to have each vale in (only) one cell? See (simple) attachment.
    Thanks in advance
    Henrik
    Attachments:
    Wavf_Index_to_Table.vi ‏25 KB

    Andre is right on.  Here is an image.
    -cb
    Attachments:
    Waveform array to table.PNG ‏10 KB

  • We want to take backup of ( RFC ,Printer, ALE setup) Tables

    Hi All,
    We want to take backup of ( RFC ,Printer, ALE setup) Tables before refresh. Could you please suggest me how we can find the related tables to export RFC etc..

    Hi Manohar,
    You can use below methods..
    RFC connections
    For releases < 6.10 SE01 -> create -> workbench req (next popup screen Fill in the BOX Target, write same SID as you are logged on to -> delete task created. Request/Task -> object list -> display object list -> change -> new entries -> r3tr tabu rfcdes -> enter -> extras -> change object function -> entire table -> save.
    Release transport, check transport log, number of exported entries should be the same as rows in table.
    FOR CLARITY:
    SE01
    Create (paper icon)
    Tick workbench request
    OK
    Add description, project id (if listed) and sid (use log if not available) and save
    Highlight unclassified transport
    Delete (dustbin icon) and confirm
    Double click on transport (lowest level)
    Change to update (pencil icon)
    Add entries u2013 PRO = r3tr / OBJ = tabu / OBJECT NAME = rfcdes
    Enter
    Click on key in next column
    Reply yes to save changes and close the warning box
    Update (pencil icon)
    Add an *
    Save
    Similarly ::::::::::
    Table TBDLS (logical names)
    Table IACORDES & IACORSITE (logical names)
    Printer definitions make transport
    SPAD -> Output devices -> Update -> Edit -> Transport -> Transport All
    User masters (if required) make transports
    SCC8 u2013> Selected profile: SAP_USER and target system
    Save batch task info from tables TBTCO & TBTCP in SE16
    thanks
    ashish

  • Printing parts of tables in varying styles

    Greetings. I need to generate a test report and I'm trying to use the
    LabView Report Generation VIs. They seem very simple and friendly, but I'm
    beginning to suspect they're not as versatile as they at first seem. :-)
    I have a string table, and I would like some elements of that table to print
    in boldface type. When I change one element to boldface on the Diagram,
    however, it turns the entire table to boldface! Is there a way to embolden
    just a single (or a few) entries of a text array, either programmatically or
    by hand? Is there a way to do it using the Report Generation VIs? Is there
    a better alternative to using the Report Generation VIs that wouldn't be too
    hard to learn and would allow more flexibil
    ity like this?
    (Note: I also want to do the same thing with a table of numeric values.)
    Thanks in advance!
    Justin Goeres
    Indio Systems, Inc.

    The report generation vi's can be modified to get them to do just about
    anything. I've been successful in modifying them for specific tasks.
    Take a look at the code to see if you can figure out the task that you
    are trying to do. Otherwise I don't know of anything else that will
    what you are trying to do (there is a commercial product that I know of
    written in LabVIEW for report generation, but I can't remember who
    sells it).
    ej
    In article <[email protected]>,
    "Justin Goeres" wrote:
    > Greetings. I need to generate a test report and I'm trying to use the
    > LabView Report Generation VIs. They seem very simple and friendly,
    but I'm
    > beginning to suspect they're not as versatile as they at first
    seem. :-)
    >
    > I have a string table, and I
    would like some elements of that table
    to print
    > in boldface type. When I change one element to boldface on the
    Diagram,
    > however, it turns the entire table to boldface! Is there a way to
    embolden
    > just a single (or a few) entries of a text array, either
    programmatically or
    > by hand? Is there a way to do it using the Report Generation VIs?
    Is there
    > a better alternative to using the Report Generation VIs that wouldn't
    be too
    > hard to learn and would allow more flexibility like this?
    >
    > (Note: I also want to do the same thing with a table of numeric
    values.)
    >
    > Thanks in advance!
    > Justin Goeres
    > Indio Systems, Inc.
    >
    >
    Sent via Deja.com http://www.deja.com/
    Before you buy.

  • Print long internal table in smartform, error SSFCOMPOSER250

    Hi experts,
    In VL03N i'm getting this error SSFCOMPOSER250 (Table row is larger than 176 cm) when printing a long internal table containing item's serial numbers. The item has 1000 serial numbers, and they are passed to the smartform in an internal table. I tried to separate in different rows, each one with 200 serial numbers but when printing the 3rd block the message appears again.
    Is it possible to print this table in the smartofrm ??
    thanks in advance,
    María

    I used SERIAL_LS_PRINT to get the serial numbers and then PROCESS_SERIALS_FOR_PRINT and got this:
    ( 768790876 - 768791875 )
    But I need to print all the serial numbers, not an interval..

  • Associative Array vs Table Scan

    Still new to PL/SQL, but very keen to learn. I wondered if somebody could advise me whether I should use a collection (such as an associative array) instead of repeating a table scan within a loop for the example below. I need to read from an input table of experiment data and if the EXPERIMENT_ID does not already exist in my EXPERIMENTS table, then add it. Here is the code I have so far. My instinct is that it my code is inefficient. Would it be more efficient to scan the EXPERIMENTS table only once and store the list of IDs in a collection, then scan the collection within the loop?
    -- Create any new Experiment IDs if needed
    open CurExperiments;
    loop
    -- Fetch the explicit cursor
    fetch CurExperiments
    into vExpId, dExpDate;
    exit when CurExperiments%notfound;
    -- Check to see if already exists
    select count(id)
    into iCheckExpExists
    from experiments
    where id = vExpId;
    if iCheckExpExists = 0 then
    -- Experiment ID is not already in table so add a row
    insert into experiments
    (id, experiment_date)
    values(vExpId, dExpDate);
    end if;
    end loop;

    Except that rownum is assigned after the result set
    is computed, so the whole table will have to be
    scanned.really?
    SQL> explain plan for select * from i;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 1766854993
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |   910K|  4443K|   630   (3)| 00:00:08 |
    |   1 |  TABLE ACCESS FULL| I    |   910K|  4443K|   630   (3)| 00:00:08 |
    8 rows selected.
    SQL> explain plan for select * from i where rownum=1;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 2766403234
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     5 |     2   (0)| 00:00:01 |
    |*  1 |  COUNT STOPKEY     |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| I    |     1 |     5 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM=1)
    14 rows selected.

  • Background job  step - Printer - Output device  table

    Hi,
    When creating background job, printer- output device also specified for every step. Which table to check for job name and output device combination ?
    Thanks.

    Hi Raj check table TBTCP

  • Lots of blank space when printing array with only last element printed

    I have a slight problem I have been trying to figure it out for days but can't see where my problem is, its probably staring me in the face but just can't seem to see it.
    I am trying to print out my 2 dimensional array outdie my try block. Inside the trying block I have two for loops in for the arrays. Within the second for loop I have a while to put token from Stringtokeniser into my 2 arrays. When I print my arrays in this while bit it prints fine however when I print outside the try block it only print the last element and lots of blank space before the element.
    Below is the code, hope you guys can see the problem. Thank you in advance
       import java.io.*;
       import java.net.*;
       import java.lang.*;
       import java.util.*;
       import javax.swing.*;
       public class javaflights4
          public static final String MESSAGE_SEPERATOR  = "#";
          public static final String MESSAGE_SEPERATOR1  = "*";
          public static void main(String[] args) throws IOException
             String data = null;
             File file;
             BufferedReader reader = null;
             file = new File("datafile.txt");
             String flights[] [];
                   //String flightdata[];
             flights = new String[21][7];
             int x = 0;
                   //flightdata = new String[7];
             int y = 0;
             try
                reader = new BufferedReader(new FileReader(file));   
                //data = reader.readLine();   
                while((data = reader.readLine())!= null)   
                   data.trim();
                   StringTokenizer tokenised = new StringTokenizer(data, MESSAGE_SEPERATOR1);
                   for(x = 0; x<=flights.length; x++)
                      for(y = 0; y<=flights.length; y++)
                         while(tokenised.hasMoreTokens())
                            //System.out.println(tokenised.nextToken());
                            flights [x] [y] = tokenised.nextToken();
                            //System.out.print("*"+ flights [x] [y]+"&");
                   System.out.println();
                catch(ArrayIndexOutOfBoundsException e1)
                   System.out.println("error at " + e1);
                catch(Exception e)
                finally
                   try
                      reader.close();
                      catch(Exception e)
             int i = 0;
             int j = 0;
             System.out.print(flights [j]);
    //System.out.println();

    A number of problems.
    First, I bet you see a lot of "error at" messages, don't you? You create a 21x7 array, then go through the first array up to 21, going through the second one all the way to 21 as well.
    your second for loop should go to flights[x].length, not flights.length. That will eliminate the need for ArrayIndexOutOfBounds checking, which should have been an indication that you were doing something wrong.
    Second, when you get to flights[0][0] (the very first iteration of the inner loop) you are taking every element from the StringTokenizer and setting flights[0][0] to each, thereby overwriting the previous one. There will be nothing in the StringTokenizer left for any of the other (21x7)-1=146 array elements. At the end of all the loops, the very first element in the array (flights[0][0]) should contain the last token in the file.
    At the end, you only print the first element (i=0, j=0, println(flight[ i][j])) which explains why you see the last element from the file.
    I'm assuming you have a file with 21 lines, each of which has 7 items on the line. Here is some pseudo-code to help you out:
    count the lines
    reset the file
    create a 2d array with the first dimension set to the number of lines.
    int i = 0;
    while (read a line) {
      Tokenize the line;
      count the tokens;
      create an array whose size is the number of tokens;
      stuff the tokens into the array;
      set flights[i++] to this array;
    }

  • How do I use Get-ADUser to get just the Managers attribute? And then get rid of duplicates in my array/hash table?

    Hello,
          I am trying to just get the Managers of my users in Active Directory. I have gotten it down to the user and their manager, but I don't need the user. Here is my code so far:
    Get-ADUser-filter*-searchbase"OU=REDACTED,
    OU=Enterprise Users, DC=REDACTED, DC=REDACTED"-PropertiesManager|SelectName,@{N='Manager';E={(Get-ADUser$_.Manager).Name}}
    |export-csvc:\managers.csv-append 
    Also, I need to get rid of the duplicate values in my hash table. I tried playing around with -sort unique, but couldn't find a place it would work. Any help would be awesome.
    Thanks,
    Matt

    I would caution that, although it is not likely, managers can also be contact, group, or computer objects. If this is possible in your situation, use Get-ADObject in place of Get-ADUser inside the curly braces.
    Also, if you only want users that have a manager assigned, you can use -LDAPFilter "(manager=*)" in the first Get-ADUser.
    Finally, if you want all users that have been assigned the manager for at least one user, you can use:
    Get-ADUser
    -LDAPFilter "(directReports=*)" |
    Select @{N='Manager';E={ (Get-ADUser
    $_.sAMAccountName).Name }}
    -Unique | Sort Manager |
    Export-Csv .\managerList.csv -NoTypeInformation
    This works because when you assign the manager attribute of a user, this assigns the user to the directReports attribute of the manager. The directReports atttribute is multi-valued (an array in essence).
    Again, if managers can be groups or some other class of object (not likely), then use Get-ADObect throughout and identify by distinguishedName instead of sAMAccountName (since contacts don't have sAMAccountName).
    Richard Mueller - MVP Directory Services

  • How to print the internal tables in grid format

    i have an internal table with 3 fields
    ITAB1
    1   a
    2   b
    3   c
    I want to print this in the gird like
    1   2   3
    a   b   c
    Can any one help me how to do it
    Thank you

    DATA: BEGIN OF S_STRUC,
    KEY1,
    KEY2,
    KEY3,
    KEY4,
    FIRST TYPE CHAR10 VALUE 'FIRST',
    SECOND TYPE CHAR10 VALUE 'SECOND',
    THRIRD TYPE CHAR10 VALUE 'THIRD',
    END OF S_STRUC.
    DATA: ITAB LIKE S_STRUC OCCURS 0 WITH HEADER LINE.
    DATA: V_INT TYPE INT4.
    FIELD-SYMBOLS: <FS>, <FS1>.
    DO 3 TIMES.
    V_INT = SY-INDEX + 4.
    ITAB-KEY1 = 'A'.
    ITAB-KEY2 = 'B'.
    ITAB-KEY3 = 'C'.
    ITAB-KEY4 = 'D'.
    ASSIGN COMPONENT V_INT OF STRUCTURE S_STRUC TO <FS>.
    ASSIGN COMPONENT V_INT OF STRUCTURE ITAB TO <FS1>.
    <FS1> = <FS>.
    APPEND ITAB.
    ENDDO.
    LOOP AT ITAB.
    WRITE: / ITAB.
    ENDLOOP.
    Regards
    vasu

Maybe you are looking for

  • Massive memory hemorrhage; heap size to go from about 64mb, to 1.3gb usage

    **[SOLVED]** Note: I posted this on stackoverflow as well, but a solution was not found. Here's the problem: [1] http://i.stack.imgur.com/sqqtS.png As you can see, the memory usage balloons out of control! I've had to add arguments to the JVM to incr

  • Quick help: Taking MBP in for repair, need to lock folders?

    hey guys, I'm supposed to drop my MBP off at an Apple Reseller today to replace the disc drive. They want me to drop it off today, but the replacement drive won't be here until tomorrow. They asked that I provide my user password so they can login an

  • Best place for spare parts for PPC 1.5 Mini?

    Hi. I'm looking for the best place to get spare parts for a Mac Mini PPC G4 1.5GHz on the net. The fan is most likely giving up, because it has recently begun to sound as the bearings in the fan are bad. Regards, /Mysteron

  • New iphone, should i return and wait for macworld?

    Hi everyone, I have a new iphone, it was purchased on 12.21.07. I love the phone, but it has been a little slow for me and has been freezing every now and then. I've been weighting the option of returning the phone and waiting for a possible upgrade

  • Sys Exec - reading the output

    I am using the System Exec.vi to send a command line to the windows command prompt: "command.com /c w32tm.exe /resync" I use this to force my PC to update the system time with a time server. When I run this command in the command prompt outside labvi