Creating and filling JTables dynamically

Hello,
How can I create and display a JTable dynamically in a Java application? In my application, I retrieve rows from a database and therefore I don't know in advance how many rows I need for my JTable (using the tablemodel). I tried to solve the problem in the following way:
1)start op applicatie with a JTable with 0 rows (screen is grey, only columns are visible)
2)run query and count number of rows.
3)create new JTable based on number retrieved in step 2 and tried to put it onto the screen.
4)run query again and fill table with values retrieved from query
The bottleneck so far is step 3. I can create a new table but I don't manage to put it onto the screen (i tried already the repaint() method)
Thanx for you help
Frits

Sure, no problem. Assume you've retrieved the following result from the database:First Name     Last Name     Age
John           Doe           25
Jane           Doe           27
Joe            Smith         40
Mary           Smith         19You create your JTable as like this:Vector headings = new Vector();
Vector rows = new Vector();
Vector cells = null;
JTable table = null;
for(int x=0; x< resultSize; x++){//resultSize is the size of your result
  cells = new Vector(); //Cells together will represent a row
  cells.add(yourResult.getTheFirstColumnForRowX()); //Pseudo-code
  cells.add(yourResult.getTheSecondColumnForRowX()); //Pseudo-code
  cells.add(yourResult.getTheThirdColumnForRowX()); //Pseudo-code
  //Now place those cells into the rows vector
  rows.add(cells);
//Create the JTable
table = new JTable(rows, headings);This code is not tested and is meant to give you an idea of how the concept can be applied. Hope it helps.

Similar Messages

  • Creating and Accessing a Dynamic View Object

    Hi,
    I'm needing to create a Dynamic View Object so to have the ability to modify the FROM and WHERE clauses in an SQL statement.
    I then need to view all the columns and rows in an adf table or something similar.
    I've read up a fair bit on similar situations, however I'm struggling with the basic framework of building the View Object.
    I know I'm wanting to use ..createViewObjectFromQueryStmt..but just unsure of the syntax in using it, especially connecting the VO to an Application Module.
    This is similar to what I've got now, located in AppModuleImpl.java
        public void createDynVO(ApplicationModule appMod, String FROMclause, String WHEREclause){
        String SQL = "SELECT JOURNAL_NAME, PERIOD_NAME FROM " + FROMclause + " " + WHEREclause;
        ViewObject vo = appMod.createViewObjectFromQueryStmt("DynamicView", SQL);
        vo.executeQuery();But how does it know what the application module is?
    Any help would be greatly appreciated!
    -Chris

    Ok, I've actually modified my approach to this.
    I've created a View Object in the design view, added it to the App Module, and then created an iterator and bound an adf table to that iterator.
    The View Object which I created has the same column names as what I am going to be getting later down the track.
    Everything is working perfectly, except that I can't seem to bind variables to the WHERE clause.
    Below is what I have got running:
        public void recreateDynView(String FromClause, String whereCompany, String whereDepartment) {
             String sql_PAGE_ITEM1 = " AND PAGE_ITEM1 LIKE :P_PAGE_ITEM1";
             String sql_PAGE_ITEM2 = " AND PAGE_ITEM2 LIKE :P_PAGE_ITEM2";
             findViewObject("DynamicView1").remove();
             String SQLStmt = "SELECT PAGE_ITEM1, PAGE_ITEM2, PAGE_ITEM3, LINE_ITEM FROM " + FromClause;
             ViewObject vo = createViewObjectFromQueryStmt("DynamicView1",SQLStmt);
             vo.setWhereClause("1=1");
               if (whereCompany != null && whereCompany.length()>0){
                   vo.setWhereClause(vo.getWhereClause() + sql_PAGE_ITEM1);
                   vo.defineNamedWhereClauseParam("P_PAGE_ITEM1",null,null);
                   vo.setNamedWhereClauseParam("P_PAGE_ITEM1",whereCompany);
               if (whereDepartment != null && whereDepartment.length()>0){
                   vo.setWhereClause(vo.getWhereClause() + sql_PAGE_ITEM2);
                   vo.defineNamedWhereClauseParam("P_PAGE_ITEM2",null,null);
                   vo.setNamedWhereClauseParam("P_PAGE_ITEM2",whereDepartment);
             vo.executeQuery();
           }However whenever I input a value into one of the bound variables, I get the following error on the page.
       1. JBO-29000: Unexpected exception caught: oracle.jbo.InvalidOperException, msg=JBO-25070: Where-clause param variable P_PAGE_ITEM1 needs ordinal index array.
       2. JBO-25070: Where-clause param variable P_PAGE_ITEM1 needs ordinal index array.In the view object which i created at design stage, I've set the binding style to Oracle Named, so it should be alright. But obviously since I'm removing the view object and creating another version of it, it doesn't have the same binding style attached by default?
    Is there a work around for this? I'm so close!
    -Chris

  • Desktop office integration : Creating and filling tables in a word document

    Hi all,
    I want to create a table in a word document and then fill it with data. The word processor interface has only 'insert_table' methods which can download the data in an ABAP internal table to an already
    existing table in a word document, but in my case I also want to create the word table,  titles etc. in the word document. Has someone experience with such kind of a requirement or have someone an example for it? 
    Kind Regards,
    Sükrü

    Hi,
    May this one will help you.
    CREATE OBJECT wordapp 'Word.Application'.
    CALL METHOD OF wordapp 'Documents' = documents.
    CALL METHOD OF documents 'Add' = thisdoc.
    CALL METHOD OF thisdoc 'Activate'.
    GET PROPERTY OF wordapp 'Selection' = selection.
    SET PROPERTY OF wordapp 'Visible' = 1.
    CALL METHOD OF selection 'TypeParagraph'.
    CALL METHOD OF selection 'TypeText'
      EXPORTING #1 = 'New Document'.
    GET PROPERTY OF wordapp 'Tables' = tables.
    CALL METHOD OF tables 'Add' = thistable.
    SET PROPERTY OF thistable 'NumRows' = 2.
    SET PROPERTY OF thistable 'NumColumns' = 2.
    or you can check
    CALL METHOD OF wordobj 'TABLEINSERTTABLE'
    EXPORTING
    #01 = 2
    #02 = 3.
    aRs

  • Create and execure a dynamic query

    hi all,
    i'm trying to write a procedure in order to create a dinamyc query and calculate a certain value.
    i coded something like this but it does not work:
    create or replace procedure CALCOLA_OPERAZIONE
    is
    sql_stmt varchar2(2000);
    colonna varchar2(2000);
    tabella varchar2(2000);
    fattore varchar2(2000);
    parametro number;
    bt number := 0;
    cursor cur is
    select cod_colonna,cod_tabella,fattore_bt from table;
    begin
    open cur;
        loop
            fetch cur into colonna,tabella,fattore;
            sql_stmt := 'select :1 * :2 into parametro from :3';
            EXECUTE IMMEDIATE sql_stmt USING colonna,fattore,tabella;
            bt:=bt+parametro;
        end loop;
    close cur;
    EXCEPTION
    WHEN OTHERS THEN
          raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    end;here the error i get:
    An error was encountered - -903 -ERROR- ORA-00903: invalid table namecan anyone help me?
    Edited by: 908335 on 6-feb-2012 1.30

    The good news is that what you want to do should be possible, but you need to take a different approach.
    The bad news is that I agree with the others and think you need to take a step back and think about whether this is a good design. Dynamic SQL is a difficult solultion to implement and (within reason) static sql is almost always more maintaintable.
    Still, if you're doing this as an exercise for your own knowledge or an assignment the technique is something like what I will put below (it will be untested). You will need to build the sql as text, execute it, and get the results. I prefer reference cursors for this kind of work although EXECUTE IMMEDIATE can be used. The solution will look something like (beware typos)
    declare
      ref_cursor sys_refcursor;
      col           varchar2(32767);
      sql_text    varchar2(32767);
      value       varchar2(1);
    begin
      col := 'dummy';
      sql_text := 'select '||col||' from dual';
      open ref_cursor using sql_text;
      fetch ref_cursor into value;
      close ref_cursor;
    end;I will leave it up to you to figure out how to adapt what you have to work like this :)

  • Create and Fill Out Forms on iPad?

    I have recently started a small business, but people must fill out a short form to recieve the item. I sometimes am away from the business when the form is needed to be filled out. I would like to save on ink and paper. So are there any apps for the iPad in which I can create a form and have people be able to fill it out and sign it right there on the iPad? I have downloaded many apps and signed up for many things, but either I can't work them orthe form must be e-mailed to the person. I need an app where I can have people fill it out and sign it right on the spot.

    Hi There
    We have a solution called iForm Pro (www.iformpro.co.uk) that would allow you to automate your forms and capture signatures, take photos and write on them and even calculate invoice values etc.
    Hope this helps
    Santy72

  • CBSpersist log automatically created and filling up drive. How do I stop sfc.exe from autorunning

    I am working on a machine where the client complained that the drive kept filling up. Upon checking I realised that over 750GB was occupied with CBS logs. These logs are usually generated when SFC.exe (System File Checker) executes. However, they are being
    created an average of 3 times a week and no one onsite is running SFC. The logs go back to 2012 so it appears that somehow SFC is autorunning..
    I could not locate a scheduled task for it in Task Scheduler. 
    Is there a wasy to confirm that there is no schedule task other than again going through every single element. 
    Any ideas as to why it is happening and how to stop it will be greatly appreciated.
    The machine is running Windows 7 Home Premium.

    Hi,
    Are we in a domain environment?
    Did this issue occur on a special machine or with all the clients in the domain?
    CBS is Component-Based Servicing, and CBS.log logged the information for CBS events. More information regarding CBS, please take a look at:
    Understanding Component Based Servicing.
    Could you please have a share with the recent log file before going further? There might be some issue keep logging in the log file. Upload it to skydrive if possible and post us the link here.
    Best regards
    Michael Shao
    TechNet Community Support

  • Create and Load Chart dynamically  in Flex

    Hi Friends,
    I want to create the chart dynamically [N numbers] . I try
    to create one line chart and add line series by action script , but
    i stuck up at how to embed that chart object in mxml code. I want
    to load the [action script created ] chart in canvas container.
    Plz help me if u have any ideas ,
    thanks
    ksam.

    what i would like to have is like this...
    XML Template :
    <class name="TaskA" getters="true" setters="true">
    <properties name="id" type="java.lang.Long" defaultValue="0"/>
    <properties name="name" type="java.lang.String" defaultValue="null"/>
    <properties name="priority" type="java.lang.Integer" defaultValue="3"/>
    </class>
    And using some java code i could generate a class at runtime, the prototype of which would be something like this...
    public class TaskA {
    java.lang.Long id=0;
    java.lang.String=null;
    java.lang.Integer priority=3;
    ..................... //Getters and Setters of the properties.
    }

  • Creating and deleting symbols dynamically

    I need help with getting this particular function implemented.
    I have 2 buttons with codes which I've added
    //Create button
    $.getJSON("content.JSON")
      .success(
      function(data){
      console.log("incoming data: ", data);
      //console.log("this is current value of var s", template);
      if (s == null)
      $.each(data, function(index, item){
      //var s = sym.createChildSymbol( "template", "content");
      s = sym.createChildSymbol( "template", "content" );
      // Creating the variable that save my new instance of mySymbol
      sym.setVariable("itemContainer"+i, s);
      console.log("item container name", s);
      s.$("title").html( item.item );
      s.$("description").html( item.description );
      s.play(index * -500);
      i++;
      //console.log("'dressbtn' inside was CLICKED");
      else
    //Delete button
    for(var p = 1; p <= i; p++)
    s = sym.getVariable("itemContainer"+p);
    s.deleteSymbol();
    i = 1;
    So the two buttons one will get the items from Json and display them, and the other will clear the symbols created.
    But I've only managed to clear the symbols on stage only once, and after that I'm getting Javascript error in event handler! Event Type = element
    The reason is because I'm trying to make an app that can get information off a json file from a webserver and able to update and display the lastest information in the app. So I've to be able to allow the user to press a button to refresh the page.
    Can anyone shine some light on this?
    Dropbox - test.zip

    Hi,
    Your issues (or troubles) come from your json file. Your json file is not well formed.
    Here is a correct one:
    {"shoes":[
    {"item":"red shoe","description":"prada red shoe"},
    {"item":"black shoe","description":"Black canvas shoe"},
    {"item":"tilith shoe","description":"tilith ballet shoe"},
    {"item":"gold shoe","description":"gold ballet shoe"},
    {"item":"ganma shoe","description":"ganma canvas shoe"}
    Then your buttons code:
    1) mybtn.click:
    //get json information and display
    $.getJSON("content.JSON")
      .success( function(data){
      console.log("incoming data: ", data);
      $.each( data.shoes, function(index, item){
      var s = sym.createChildSymbol( "template", "content");
      s.$("title").html( item.item );
      s.$("description").html( item.description );
      s.play(index * -500);
      } );//each
       } );//success
    2) btn_2.click:
    //deleting shoes (symbols)
    var symbols = sym.getChildSymbols();
    $.each(symbols, function(index, item){
      console.log("symbols on stage: ",item.getSymbolTypeName());
      if (item.getSymbolTypeName() == "template") item.deleteSymbol();
    Download link: test-2 - copie.zip - Box

  • Create and fill combobox at runtime

    Hi,
    I can now create a combobox, as a child of a gridpanel, at runtime:
    HtmlSelectOneMenu combobox2 = new HtmlSelectOneMenu();
    combobox2.setId("dropdownProject");
    gridPanel1.getChildren().add(combobox2);
    Can someone help me out with how to set the items in the combobox, at runtime?
    From my previous OO-experience I thought I could create a model (DefaultSelectItemsArray?) and attach that to the viewer (the combobox) but I can't find any way of doing that.
    I must say that I'm a java beginner so that may be part of the problem ;-)
    Thanks already,
    Bart.

    Hi again,
    It took me 4 hours but I got it to work myself.
    For the archive, here's the code:
    ArrayList dropdown1Options = new ArrayList();
    dropdown1Options.add(new SelectItem("Choice 1","My First Project"));
    dropdown1Options.add(new SelectItem("Choice 2","My Second Project"));
    dropdown1Options.add(new SelectItem("Choice 3","My Third Project"));
    UISelectItems dropdown1SelectItems = new UISelectItems();
    dropdown1SelectItems.setValue(dropdown1Options);
    HtmlSelectOneMenu dropdown1 = new HtmlSelectOneMenu();
    dropdown1.setId("dropdownProject");
    dropdown1.getChildren().add(dropdown1SelectItems);
    gridPanel1.getChildren().add(dropdown1);
    The link I missed was the one between the HtmlSelectOneMenu and the UISelectItems.
    Appearantly you bind them using the getChildren().add() method. (?)
    I'm gonna give myself the duke dollars! :-)
    Cheers,
    Bart.

  • How to create and use dynamic queue in JMS

    Plz tell me how to create and use a dynamic queue in jms and can reciever file lookup it as it lookup any server configurred queue(written in the server).

    Hi,
    We can use Azure File services to do this, for more information, please have a look at this article:
    http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/12/introducing-microsoft-azure-file-service.aspx. The Azure File service exposes file shares using the standard SMB 2.1 protocol. Applications running in Azure can now easily share files between
    VMs using standard and familiar file system APIs like ReadFile and WriteFile.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Creating dynamic sized arrays and filling them automatically on speedy 33

    hi all,
    I am trying to create dynamic sized arrays on Speedy-33. Specifically, depending on the user input, I want to be able to create
    arrays with 128 or 256 elements and fill them automatically. However,
    array constant element is fixed for Speedy 33; thus I have to manually set the
    size of the array with the mouse and enter the values in to the array by
    myself. I want to make this tedious process automatic. Would this be possible? thanks so much for comments!
    ~casiopea

    Casiopea,
    There is a really great article on using arrays with LabVIEW DSC which can be found here:
    How Can I Be Successful With Arrays In the LabVIEW DSP Module?
    One of the biggest things that should be noted about DSP is that there is no dynamic memory allocation.  Your array size must be fixed, and thus, your array needs to be initialized by using a constant. 
    An easy way to initialize an array constant that has many elements that are all the same is to simply create a numeric constant that has the value that you want.  Then, create a new blank array constant and drag the numeric into it.  In the index input for the array constant, type in the index of the last element that you want to be initialized.  Then type in the value in the element that is displayed and all of the elements before it will be initialized to the default value of the numeric constant that you dropped into the array constant.  I hope this helps.  I would really recommend reading through that article, as it has a lot of great information about using arrays with DSC.
    Brian Coalson
    Software Engineer
    National Instruments

  • Creating Poplist and filling up values in it dynamically.

    Hi,
    I have created a poplist based on a viewObject.It works fine.
    Is it possible to populate values into poplist at runtime.
    ie ..I have a String array and I want to show it in the poplist.
    String[] names = {"ABC","XYZ","PQR"};
    Is it possible to create a poplist to show these values programmetically?
    In a JSP I would do like this..
    <SELECT>
    <%
    for(int i=0;i<names.length;i++)
    {%>
    <OPTION><%=names[i] %>
    <%
    }%>
    </SELECT>
    Any such similar solution for this problem?
    Thanks,
    Gowtam

    Hi Tapashray,
    Thanks for the reply.
    I have few doubts on your answers.As I am new to OA, my questions might look silly.I have written my interpretation.Please validate and give me some hint to solve it.Thanks :)
    1.Create a VO at designtime.
    - VO must not be based on any EO but should be SQL based and as the data is not picked from Database, what "query" need to be written for the query section in the wizard?
    2.populate the VO attributes with values from your array at runtime
    - The values will be poplulated into VO and poplist simultaneously(dynamically) at runtime OR VO will be populated in prior and at runtime only poplist will be loaded?
    - How to populate values into VO?
    3.remember to use Picklist View Instance property
    - Do i need to specify the View Object Name here? ex:"NamesVO"
    thanks,
    Gowtam

  • How to create new rows in a JTable dynamically?

    I want to add new rows to a JTable dynamically based on my resultset from the database .
    How to do ?
    Please help me
    Thanks in advance

    Thank u for ur reply .But still i need to clarify something.
    I've used the below code to create a basic table within my frame.
    Object[][] data = {      {"dilipp", "r",      "early", "10","20"}};
    String[] columnNames = {"First Name", "Last Name", "payment", "from", "to"};
    table = new JTable(data, columnNames);
    after this i connect to database and query .The values returned are to be populated in the table created above through say a button "Next" month.
    now my button event goes like this :
    public void actionPerformed(ActionEvent e)
         if (e.getActionCommand().equals("next"))
    here i need to add a new row for the values
    How to add here ?
    please tell me

  • Creating and Binding View Objects dynamically : Oracle Jdeveloper 11g

    Hello,
    We are trying to create and bind view objects dynamically to adf data visualization components.
    The view object is a result of multiple tables.
    We are using Oracle JDeveloper 11g Technical Preview. ( can't upgrade to TP2 or TP3 now).
    We have found this : http://radio.weblogs.com/0118231/stories/2003/07/15/creatingUpdateableMultientityViewObjectDefinitionsDynamically.html on our search for the same.
    The sample application however, is in 10g , hence required migration.
    Also, it was a standalone application with the TestClient.java having a main() method.
    Our requirement is for Web Application; we use Adf+jsf .
    Guidance of any sort is very much appreciated.
    Thanks in advance.
    -Anil Golla

    Hi,
    there also exist a forum for JDeveloper 11: JDeveloper and OC4J 11g Technology Preview
    What you are trying todo is not trivial because you need to not only dynamically create the VO, you would also dynamically need to create the binding meta data for it (assuming you use ADF). Not sure if the API to modify the binding is public, so posting it on the JDeveloper 11 forum bears a glimpse of hope for an answer
    In JDeveloper 10.1.3 you can't do this
    Frank

  • How to create a webdynpro view dynamically and embed into view container?

    Hi all,
    Anyone knows how to create a view dynamically and embed the view into an existing view container?
    My layout looks like this:
    I have an existing view named main_view.
    Inside main_view, I create a view ui container named vcu_view.
    I embed the main_view into my window.
    I need the codes to create a view dynamically and embed the view into the view container. Anyone have any idea?
    Thanks in advance.
    Rgds,
    Siong Chao

    hi Siong Chao   ,,
    empty view insence ..( create a view without any UI element in it  ) in design time ..
    >
    Siong Chao wrote:
    > Hi Chinnaiya,
    >
    > How do you create an empty view dynamically then? Thanks in advance.
    i think we cannot create a new view dynamically because it is a webdynpro restriction ..
    NOTE: experts correct me if i am wrong in this answer
    Regards
    Chinnaiya P

Maybe you are looking for

  • Typing Test

    What is the best algorithm to score a typing test? A user types from a sample. You compare the two samples and determine how accurate the sample is. A missed word, an extra word or a misspelled word are wrong. Having more than 2 spaces between words

  • Sending sound from my TV into my Samsung Home Theater

    Hi all - I bought a Samsung HT-Z420 Home theater speaker system and I can't figure out how to get the sound from regular cable tv through the speakers.  My TV has a audio out, so I plugged in the red and white cables and then connected to the AUX in

  • Phone in works, phone out doesnt. Broadband works.

    Need help please. Broadband is fine, incoming calls are fine but cant dial out unless i take apart the box that the wiring goes into. It doesnt work on the outside connection i have to unscrew the two screws and plug it into the internal connector. I

  • How to use analytical function in this case

    SELECT COUNT (rms.status_code) rms_status_count, rms.status_name rms_status_name, TO_CHAR (rtd.add_date, 'MON')|| ' '|| TO_CHAR (rtd.add_date, 'YYYY') month_year, MAX (rtd.add_date) date_for_sort FROM ri_mast_status rms, ri_tran_data rtd WHERE rtd.st

  • OIM Disaster Recovery Setup

    We are in the processing of completing setup of our production environment with OIM 9.1.0.2. Our setup is running on WAS 6.1 in a two node cluster. We run to an Oracle database. For DR we were planning to take a backup of the production database and