Problem adding columns and rows in JTable

hi, hope somebody can help me
i have some problems when i add columns and later i try to set number of rows in JTable, ocurr some exceptions
my code is something like thisJTable tabla = new JTable();
TableColumn tc = new TableColumn();
tc.setHeaderValue("col1");
tc.setPreferredWidth(20);
tabla.getColumnModel().addColumn(tc);up to here everything goes well, my table shows the column, but when i add this line((DefaultTableModel)tabla.getModel()).setNumRows(1);ocurrs the next exception
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0....
any ideas????

oks, that would work when the JTable is created, but now we say that I require a method which adds a new row to the JTable a some moment of execution
Look some of my code
i have this in a JFrame...
JTable tabla = new JTable();
DefaultTableModel tm = new DefaultTableModel();
tabla.setModel(tm);
agrCol("Col1", 80);
agrCol("Col2", 160);
agrFil();
agrFil();
agrCol(String col, int lon) {
  tm.addColumn(col);
  tabla.getColumn(col).setPreferedWith(lon);
agrFil() {
  tm.setRowCount(tabla.getRowCount() + 1);
the jtable shows the 2 columns and 2 rows, but the setPreferedWith work only in the last col, i'm confused

Similar Messages

  • How to get the current selected column and row

    Hi,
    A difficult one, how do i know which column (and row would also be nice) of a JTable is selected?
    e.g.
    I have a JButton which is called "Edit" when i select a cell in the JTable and click the button "Edit" a new window must be visible as a form where the user can edit the a part of a row.
    Then the column which was selected in the JTable must be given (so i need to know current column) and then i want the TextField (the one needed to be edited) be active with requestFocus(). So it would be
    pricetextfield.requestFocus();
    Problem now is that i have to click every time in the window the JTextField which was selected in the JTable. I have chosen for this way of editing because my application is multi-user and it would be too difficult for me when everybody did editing directly (catch signals, reload data, etc.).
    My question is how do I know the current column and the current row in a JTable?

    I'm not sure what your mean by the "current" row or column, but the following utility methods return
    which row and column have focus within the JTable.
    public static int getFocusRow(JTable table) {
        return table.getSelectionModel().getLeadSelectionIndex();
    public static int getFocusColumn(JTable table) {
        return table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
    }

  • Highlighting columns and rows

    Hello,
    We were wondering if anyone has some suggestions on the following problem:
    A JTable is created and populated with zeros (0's) and ones (1's). We need to search through each cell of the JTable and find where the 1's are located. Once found, we need to highlight the entire column and row in which the 1 is located. How can highlighting be done? What we mean by highlighting is to set a particular color to the row and column. Can anyone provide a code snippet?
    Thanks!

    My example in this thread might give you some ideas:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=397802

  • Inserting total column and row

    Hello All,
    I'm new to WebI and BOBJ and I'm having some issue with my first report.  I've tried searching the forum for this same issue (or something similar) and came across nothing.  Any help is greatly appreciated!
    I'm having a problem inserting a Grand Total column and row to my report. Here's a sample layout of my report:
    *Tech Type | Project | Role | Key Fig1 | Key Fig 2 | Key Fig 3 | Key Fig 4|*
    Proj 1
    Subtot
    Proj 2
    Subtot
    etc
    In one tab the key figures are grouped by month and I also created four tabs (one tab for each key figure) that lists the key figures by month.
    What I wish to do is insert one row at the end of the report which sums the key figures vertically and a column that adds the key figures horizontally.  I've tried to do SUM but that inserts a row/column after every key fig. I've also tried to do a count and insert a SUM formula with the same effect (a row/column is inserted after every key figure).
    Any suggestions?
    Thanks,
    Joaquim M.

    Joaquim,
    Through your posting it's hard to visualize what is happening, other than you are not satisfied with the results.  Here are the steps for adding a sum to a horizontal grid with perhaps two columns of information (month, figures).  After the grid is presented, left-click once on the data of figures (do not click on the header cell of figures, click on any cell just below the header).  Once you left-click the column will appear with a "grey" highligting.  Next is to click on the "sigma" icon drop-down and choose "Sum".  Once you click sum a new row at the very bottom of your grid should appear, summarizing [figures].
    Thanks,
    John

  • Read words from text file by delimiter as columns and rows

    Hi All,
    I need your help as i have a problem with reading string by delimiter. i have used various tech in java, but i can not get the result as expected.
    Please help me to get the string from text file and write into excel . i have used a text file.
    problem
    get the below as string by delimiter
    OI.ID||'|'||OI.IDSIEBEL||'|'||OI.IDTGU||'|'||OI.WORKTYPE||'|'||OI.UTR_FK
    read the below as string by delimiter
    "50381|TEST_7.15.2.2|09913043548|Attivazione|07-SEP-10
    now i need to write the above into excel file as columns and rows.
    there are 5 columns and each corresponding values
    the outut excel should be
    OI.ID OI.IDSIEBEL OI.IDSIEBEL OI.WORKTYPE OI.UTR_FK
    50381 TEST_7.15.2.2 09913043548 Attivazione 07-SEP-10
    i tried in diffrerent techinq but not able to get the resule. pls help me
    Thanks,
    Jasmin
    Edited by: user13836688 on Jan 22, 2011 8:13 PM

    First of all, when posting code, put it between two tags.
    Second of all, the pipe is a special character in regex, so you need to escape it as
    .split("\ \|");
    Erh. So 2 backslashes before the pipe character. Stupid forum won't post it.
    Edited by: Kayaman on Jan 24, 2011 9:35 AM
    Edited by: Kayaman on Jan 24, 2011 9:35 AM
    Edited by: Kayaman on Jan 24, 2011 9:36 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Increase report size (columns and rows) in portal

    Hi all,
    Hope someone can help me with this.  I don't have any experience administering the reporting portal, hopefully this is an easy question.
    The portal displaying BI queries shows only about 10 columns and 10 rows at a time.  This is annoying since users have to scroll around to see all the rows and columns.  Where can I adjust the number of columns and rows displayed?
    Thanks,
    M.

    Hi M.B.
    Open WAD ( Bex Web Application Designer ) in which , you have assigned BI query. follow the steps for changing no of rows & columns.
    Step 1.    Properties   -  > select Web Items parametes.
    Step 2.   select  Ananlysis
    Step 3.   Scroll down  -> paging  -> here you can change no of rows & columns.
    Hope it will serve your query. If problem solved , closed this thread .
    Regards,
    Anand Mehrotra.

  • FREEZE COLUMNS AND ROWS IN WEB REPORT - PLEASE ADVISE ME

    Hi Experts,
    I have a web template that contains a query. My customer wants to freeze columns and rows in this report like we do in Excel. I know that in BW 3.5 this is not a standard feature of Table item. In forum I have found some messages regarding with this issue. I inserted a JavaScript code that I have found in forum, but this does not help. A codewriter wrote some other JaveScript for example  alert(), that works but some part of taken code from forum such as defined functions do not work.
    Other solutions advised in forum such as fixing row numbers or column numbers do not fix my problem.
    My questions:
    1 -  In new version of BW, BI 7.0 have this issue with WAD in standard been solved?
    2 - Does it really possible at the same time rows and columns to freeze? I want to freeze 2 rows from top, 2 columns from left.
    Could anyone have an idea?
    Best regards,
    Songul

    Hello,
    This will be implemented with SPS13.
    https://websmp204.sap-ag.de/~sapidb/011000358700004483762006E
    And before SPS13, i frame is useful to realize what you want to do. Using 2 "Analysis" web item. and display of 1st analysis web item is restricted only thin the header of the table and the 2nd Analysis web item is used as "table". display of this "analysis" is also restricted to 10 - 30 rows.
    but this consume hardware resource.
    <sample>
               <div style="OVERFLOW: auto; WIDTH: 1000px; HEIGHT: 20px" >
                   <bi:ANALYSIS_ITEM name="ANALYSIS_ITEM_2" designwidth="400" designheight="20" >
                       <bi:DATA_PROVIDER_REF value="DP_1" />
                       <bi:NEW_LINES_COUNT value="0" />
                       <bi:NEW_LINES_POSITION value="TOP" />
                       <bi:DATA_ROW_FROM value="1" />
                       <bi:DATA_ROW_TO value="0" />
                   </bi:ANALYSIS_ITEM>
               </div>
               <div style="OVERFLOW: auto; WIDTH: 1000px; HEIGHT: 200px" >
                   <bi:ANALYSIS_ITEM name="ANALYSIS_ITEM_1" designwidth="400" designheight="200" >
                       <bi:DATA_PROVIDER_REF value="DP_1" />
                       <bi:DATA_COLUMN_FROM value="1" />
                       <bi:DATA_ROW_TO value="0" />
                   </bi:ANALYSIS_ITEM>
               </div>
    Kind regards,
    Masaaki

  • Setting the ALV Hierarchy tree with grid line between the columns and rows

    Hi Experts,
    I would like to ask if there is any suggestion on setting the ALV hierarchy tree to be separated by grid line between the columns and rows just like how it is display the same way in normal ALV grid.
    Thanks in advance.

    Hi Lin,
    The requirement which you have stated is not possible.
    Lin,
    Also i have a query regarding BADI ZME_PROCESS_REQ_CUST, which you had raised on SDN. You have marked the question as solved/answered.
    Changing the data of a customize field in purchase requisition
    Could you please let me know, the steps you did to update the screen fields through the BADI.
    I would really appreciate your reply, because i am facing exactly the same problem which you have mentioned.
    Thanks,
    Best regards,
    Prashant

  • Excel tables... columns and row formatting after I update the indesign page

    When my excel table gets updated in indesign I lose formatting (hight/wide) for the columns&rows. There are 26 columns and each one is a difference size. Do I have to formatting (hight&wide) each column and row every time the excel table is updated?

    We have many publications with statistical tables, which are done in excel. We want to try to do some publications with only tables and do it in-house. The problem is when we place the table in indesign and finish formatting the table. We will get a updated table that needs to be updated in indesign. But when we do we update we lose all of the indesign formatting. Fixing the fonts, type size, etc is easy but how do we get back the all column widths.

  • Numbers-freezing columns and rows

    Can you freeze columns and rows in numbers although they are not designated as headers?

    FYI   I was looking for information in these old posts on the Freeze function in Numbers.  
    After looking through numerous posts and finally talking with an Apple Tech, we found that the freeze function was not in Number 08, but added in Number 09.   We were both surprised that this basic spreadsheet function was missing from 08
    With this function you can lock/freeze the top row and/or column so as you scroll through the spreadsheet, you can see you first rows or columns while looking at the data in the middle of the  spreadsheet.  
    I am not an Apple representative, but the only way to fix this and other flaws in Number 08 is to upgrade to 09 for $19.99.   Hope this helps.

  • Can I paste and keep the same columns and rows?

    Paste problems. I regularly download data from the Transport for London, Oystercard website. When I used Windows I could highlight and copy on their webpage (displayed in columns and rows) and when I pasted into Excel it pasted the data in the same format (columns and rows). With iPages when I try this it pastes everything into a single downwards column. Paste and Match style does not seem to alter this just the font etc. Am I able to paste in iPages in the same format as I copy.

    I'm guessing you're using Safari to access the web site. The problem is with Safari, not Pages (no "i") or Numbers. Safari just doesn't "understand" tables in web pages & puts lots of spaces and/or returns instead of the needed tabs. I long since gave up & use Camino or FireFox for copying the tables to Numbers or any other program I want the data separated by tabs. There are some web sites, Discover Card is one, that appear to have tables but the data doesn't copy as such.

  • Printing Columns and rows

    public class arraydd {
    public static void main(String[] args) {
    int [][] array =
    {1,2,3},
    {4,5,6},
    {7,8,9},
    {10,11,12},
    {13,14,15},
    for (int row = 0; row < array.length; row++)
    for (int column = 0; column < array[row].length; column++)
    System.out.print(array [row][column] + " ");
    System.out.println();
    int row = 3;
    for(int col = 0; col<array[row].length; ++col)
    System.out.printf ("%8d", array [row][col]);
    }Hello all
    Im trying to print all the elements of for 4 (position 3) & all the elements in the 3rd column
    i have the code for print all the elements of for 4 (position 3) as follow's :
    int row = 3;
    for(int col = 0; col<array[row].length; ++col)
    System.out.printf ("%8d", array [row][col]);
    }{but my problem is that it expects a class of some kind , could someone explain this to me ?
    also how do you print all the elements in the 3rd column ?

A: Printing Columns and rows

public class arraydd {
public static void main(String[] args) {
         int [][] array =
         {1,2,3},
         {4,5,6},
         {7,8,9},
         {10,11,12},
         {13,14,15},
            for (int row = 0; row < array.length; row++)
            for (int column = 0; column < array[row].length; column++)
                System.out.print(array [row][column] + " ");
               System.out.println();
        int row = 3;
        for(int col = 0; col<array[row].length; ++col)
        System.out.printf ("%8d", array [row][col]);
        }I hope you find this indentation to be helpfull as im not exacly sure how it should be indented
Could i ask someone for help with how to solve this problem.
Thankyou

public class arraydd {
public static void main(String[] args) {
         int [][] array =
         {1,2,3},
         {4,5,6},
         {7,8,9},
         {10,11,12},
         {13,14,15},
            for (int row = 0; row < array.length; row++)
            for (int column = 0; column < array[row].length; column++)
                System.out.print(array [row][column] + " ");
               System.out.println();
        int row = 3;
        for(int col = 0; col<array[row].length; ++col)
        System.out.printf ("%8d", array [row][col]);
        }I hope you find this indentation to be helpfull as im not exacly sure how it should be indented
Could i ask someone for help with how to solve this problem.
Thankyou

  • How to fix skewed table columns and rows after re-import XML

    My question is regarding XML Import in InDesign CS3.
    I have a XML that has a table of 5 columns and 5 rows, when I import it into InDesign, the table shows up fine with 5 columns and 5 rows. However when I revise my table to have an additional column, and re-import the XML file, the table gets updated, but instead of with an additional column, it gets 'appended' with an additional row instead (InDesign seems to blindly replace each cell from left to right, top to bottom, and ends up with 6 rows instead). The XML file specifies the number of columns and rows (5 and 5 before, 5 and 6 after), why doesn't InDesign recognize it and automatically add a new column when I re-import the file?  Is this problem fixed in CS5.5? Is there a script to fix this?
    Here is an example of my old XML vs new XML:
    Old:
    <frame5>
    <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" aid:table="table" aid:trows="5" aid:tcols="5">
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1"></Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2006</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2005</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2004</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2003</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores at beginning of period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">678</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores opened during the period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">36</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">50</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">59</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">79</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores closed during the period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">13</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">9</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">7</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Total stores at end of period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">869</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
    </Table>
    </frame5>
    New:
    <frame5>
    <Table xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
    xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" aid:table="table" aid:trows="5" aid:tcols="6">
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1"></Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2007</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2006</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2005</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2004</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">2003</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores at beginning of period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">123</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">678</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores opened during the period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">456</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">36</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">50</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">59</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">79</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Stores closed during the period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">789</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">13</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">9</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">7</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">4</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">Total stores at end of period</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">1368</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">869</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">846</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">805</Cell>
    <Cell aid:table="cell" aid:crows="1" aid:ccols="1">753</Cell>
    </Table>
    </frame5>

    What I mean is, right now there is a "workaround" which requires a user to manually add an extra column before re-importing the XML (with an extra column), otherwise the results get skewed. If by providing a script we can simply ask the user to "run" it, it would be a more "acceptable" solution.  
    Right. So, one solution would be to use Convert Text to Tables. If you find that works for you, then you can script it.
    That's why I asked you...
    Of course if nothing is required from the user other than simply re-importing, then that would be the best solution.
    Well, one could imagine a script that was attached to the re-import command, or to the link update notification, but probably the first step is to get something that works reasonably well without automating it completely. Especially because triggers to run scripts silently can introduce hard-to-debug problems.
    Sure we can switch to use "CALS table and see if this works. The question is, why should we need to? In the 2nd XML there is clearly a different "aid:tcols" value, and yet InDesign seems to ignore it and assume the same # of columns? This sounds like an Indesign bug, can someone confirm? Is there any plans to fix this?
    Not to be snarky, but do you want it to work or not? There are the tools you have and the tools you wish you had, and you can't really do much with the ones you wish you had. I'm kind of assuming you are looking for a solution today, not a solution in 2013.
    Yes,  I believe two of us have confirmed this appears to be a bug.
    Plans to fix? Well, we can't really tell you. You could try asking Adobe, but that's not easy information to get out. But you can certainly open a support case at http://adobe.com/go/supportportal and ask. It's not like we have special information here...
    But you're probably better off filing a bug first, in that same fashion.
    But let's assume no one had filed the bug. CS6 is expected in the March/April 2012 timeframe. That means that they're probably just putting the finishing touches on it right now, and it's going to be very difficult to fix things in it now. So then the earliest you'd likely get it fixed in CS6.5/CS7/whatever which presumably comes out by 2Q2013, and that's assuming Adobe decides to fix it...
    I also can't find much documentation on how to update my table to a "CALS table", any examples?
    Try this thread:
    Re: Importing a CALS table into InDesign CS3

  • How to enter a data into the specified column and row in a created table

    Hi,
    I want to enter some data to specified column and row in a already created table. Please let me know how to do this.
    Regards
    Shivakumar Singh

    A table is just a 2D array of strings. Keep it in a shift register and use "replace array element" to modify the desired entry programmatically.
    If you want to modify it manually and directly from the front panel, make it into a control and type directly into the desired element. (In this case your program would need to write to it using a local variable).
    Atttached is a simple example in LabVIEW 7.0 that shows both possibilities.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChangeTableEntries.vi ‏41 KB

  • I use "element 12" and want  like in the old PS version due Automating and Contact  II upload multiple filesand print them with any columns and rows on the same page . How does it work?

    I use "element 12" and want  like in the old PS version due Automating and Contact  II upload multiple filesand print them with any columns and rows on the same page . How does it work?

    Can you supply a link?

  • Maybe you are looking for