Create new JTable based on selection of previous table

Hello All,
I want to create a sort of selection table. I have a fairly large JTable that is row selectable. I want the user to be able to select some rows, and then create a smaller table just displaying the selected rows.
The current problem I am having (I say current b/c I'm sure more will follow) results from users rearranging the columns.
Example) When columns are arranged as: A B C. Then the user rearranges to B A C. The getColumns() method returns the columns in the right order (B A C), but the getData() method returns the data in the old arrangement. So the data now does not match up to the column names.
Here are the two methods I mention above (note: This class extends from JTable, so the "super" calls call back to JTable):
* Retrieves data from table.
public Vector getData() {
  Vector data = ((DefaultTableModel)super.getModel()).getDataVector();
  return data;
* Retrieves the column names
public Vector getColumns() {
  Vector fieldNames = new Vector();
  Enumeration e = super.getTableHeader().getColumnModel().getColumns();
  while(e.hasMoreElements()) {
    String name = (String)((TableColumn)e.nextElement()).getHeaderValue();
    fieldNames.add(name);
  return fieldNames;
}I hope I made my problem clear. Thanks for any/all suggestions!

Ah! A vector of vectors is returned from the getData call.
I assumed is was a vector as follows:
A -> __data for A__
B -> __data for B__
C -> __data for C__
But no, its:
Row1 -> __A B C__
Row2 -> __A B C__
Row3 -> __A B C__
etc...
So after trying to code, I realized what I was doing. I was rearranging rows! Not columns! Why would JTable set up its rows in this fashion? Wouldn't it be more efficient to have the primary vector be the order of the columns? It seems that would make things much easier. Well, that's my little rant after finally realizing that my code wasn't broken, it was doing exactly what I told it to do!

Similar Messages

  • Creating new task based om completion of previous task in R17

    Hi All,
    Currently in R16, the workflow of creating new task based on "When Modified Record Saved" for Activity entity is not possible.
    Meaning, for ACTIVITY it is not possible to generate new task based on completion of previous one, for example.
    Will it be different in R17? will it be different in the future? Or we will always need to use web service to have this functionality?
    Thanks
    Guy

    I've looked at both threads, and there simply isn't enough information for me to tell you what is wrong.  Please collect a trace (instructions in General forum) and open a case with CSS.  CSS can provide more in depth analysis than what a forum
    post allows. 
    As a shot in the dark, I have seen the issue outlined in the following KB article cause this exact same error message and symptom,
    http://support.microsoft.com/kb/967902
    Best Regards, Mike Briggs [MSFT] -- posting provided "AS IS" with no warranties and confers no rights

  • Create a JTable based on an ArrayList containing instances of a class.

    I have a class, IncomeBudgetItem, instances of which are contained in an ArrayList. I would like to create a JTable, based on this ArrayList. One variable is a string, while others are type double. Not all variables are to appear in the JTable.
    The internal logic of my program is already working. And my GUI is largely constructed. I'm just not sure how to make them talk to each other. The actually creation of the JTable is my biggest problem right now.

    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    public class TableDemo extends JPanel {
         private boolean DEBUG = false;
         public TableDemo() {
              super(new GridLayout(1, 0));
              ArrayList<MyObject> list = new ArrayList<MyObject>();
              list.add(new MyObject("Kathy", "Smith", "Snowboarding", new Integer(5),
                        new Boolean(false)));
              list.add(new MyObject("John", "Doe", "Rowing", new Integer(3),
                        new Boolean(true)));
              list.add(new MyObject("Sue", "Black", "Knitting", new Integer(2),
                        new Boolean(false)));
              list.add(new MyObject("Jane", "White", "Speed reading",
                        new Integer(20), new Boolean(true)));
              JTable table = new JTable(new MyTableModel(list));
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              table.setFillsViewportHeight(true);
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Add the scroll pane to this panel.
              add(scrollPane);
         class MyObject {
              String firstName;
              String lastName;
              String sport;
              int years;
              boolean isVeg;
              MyObject(String firstName, String lastName, String sport, int years,
                        boolean isVeg) {
                   this.firstName = firstName;
                   this.lastName = lastName;
                   this.sport = sport;
                   this.years = years;
                   this.isVeg = isVeg;
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              ArrayList<MyObject> list = null;
              MyTableModel(ArrayList<MyObject> list) {
                   this.list = list;
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return list.size();
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   MyObject object = list.get(row);
                   switch (col) {
                   case 0:
                        return object.firstName;
                   case 1:
                        return object.lastName;
                   case 2:
                        return object.sport;
                   case 3:
                        return object.years;
                   case 4:
                        return object.isVeg;
                   default:
                        return "unknown";
              public Class getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
          * Create the GUI and show it. For thread safety, this method should be
          * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableDemo newContentPane = new TableDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();
    }

  • How to create a report  based on selected item from Select list?

    Hi,
    I have created a tables_LOV based on:
    select table_name d, table_name r from user_tab_cols
    where column_name like '%_type%'
    Then I created a page item ListOfTables,  Display as select list and pointing to tables_LOV.
    I run the page, and i can select the table i want from the drop down list.
    How to create a report  based on the selected item? (ex: select * from selected_table)
    many thanks in advance
    Salah

    Hi Salah,
    Allright, have a look at this page: http://apex.oracle.com/pls/apex/f?p=vincentdeelen:collection_report
    I think that simulates what you're trying to accomplish. I've set up the simplest method I could think of.
    The report is based on an apex collection. If you are not familiar with that, you should study the documentation: APEX_COLLECTION
    To recreate my example you should:
    1) create an (interactive) report on your collection
    SELECT *
       FROM APEX_collections
    WHERE collection_name = 'MY_COLLECTION'
    2) create a page_item select list for the tables you want to display (in my case this is called "P38_TABLES" )
    3) create a dynamic action that triggers on change of your select list page_item. The dynamic action must be a PL/SQL procedure perfoming the following code:
    declare
      l_query varchar2(4000);
    begin
      l_query := 'select * from '||:P38_TABLES;
      if apex_collection.collection_exists
            ( p_collection_name => 'MY_COLLECTION' )
      then
        apex_collection.delete_collection
          ( p_collection_name => 'MY_COLLECTION' );
      end if;
      apex_collection.create_collection_from_query
        ( p_collection_name => 'MY_COLLECTION'
        , p_query           => l_query
    end;
    Make sure you add your page_item to the "Page Items to Submit" section.
    4) Add an extra true action that does a refresh of the report region.
    Here are two pictures describing the da:
    http://www.vincentdeelen.com/images/otn/OTN_COLLECTION_REPORT_DA1.png
    http://www.vincentdeelen.com/images/otn/OTN_COLLECTION_REPORT_DA2.png
    Good luck and regards,
    Vincent
    http://vincentdeelen.blogspot.com

  • Mail does not create new emails based on the highlighted mailbox, but rather the receiving mailbox of whatever individual email happens to be highlighted. This was not the case prior to Lion. Is this a bug or an error on my part?

    Mail does not create new emails based on the highlighted mailbox, but rather according the receiving mailbox of whatever individual email happens to be highlighted. This was not the case prior to Lion. Is this a bug or an error on my part? (I do have the setting for creating new emails from the highlighted mailbox checked.)

    The questions about time was not only because of thinking about the Time Machine, but also possible impact on recognizing which messages remaining on a POP server (doesn't apply to IMAP) have been already downloaded. In the Mail folder, at its root level, in Mail 3.x there is a file named MessageUidsAlreadyDownloaded3 that should prevent duplicate downloading -- some servers may not communicate the best with respect to that, and the universal index must certainly be involved in updating that index file. If it corrupts, it can inhibit proper downloading. However, setting the account up in a New User Account and having the same problem does not point that way, unless your POP3 server is very different from most.
    That universal index is also typically involved when messages are meant to be moved from the Inbox to another mailbox -- in Mail 3.x the message does not move, but rather is copied, and then erased from the origin mailbox. That requires updating the Envelope Index to keep track of where the message is, and should keep track of where it is supposed to have been removed after the "Move".
    Ernie

  • Read contents of excel and create new List based on excel

    HI,
    I have a excel file, which is uploaded in a document library. I am using C# and VS 2010.
    The excel file contains multiple sheets. I want to read the contents of the excel file and create a new List based on the contents of the excel file.
    How to achieve this programmatically?
    Thanks

    Hi.
    You can user OpenXML SDK to read excel Data.
    http://msdn.microsoft.com/en-us/library/office/bb448854.aspx
    Here an example of use.
    http://zsvipullo.blogspot.it/2011/08/excel-helper-leggere-un-file-xlsx.html
    Regards,
    Bubu
    http://zsvipullo.blogspot.it
    Please mark my answer if it helped you, I would greatly appreciate it.

  • Automator/Applescript to Create New Pages Doc in Selected Folder

    When working in Finder I'd like to be able to create a folder, and then (still within Finder) create a number of Pages documents inside that folder. This would help in organizing complex projects, and would be preferable to creating the documents (from the bottom up) in Pages and then laboriously assigning each document to a different folder.
    I've tried various solutions in Automator and Applescript but nothing has worked.
    For example:
    try
    tell application "finder" to set myFolder to (folder of the front window)
    on error -- no open folder windows
    set myFolder to path to desktop folder
    end try
    tell application "Pages"
    activate
    set myDocument to make new document with properties {path:myFolder}
    end tell
    But this gets an error "Can't make [the selected folder] of application "Finder" into the expected type. (-1700).
    In automator, I've tried to do the following:
    1. Get Selected Finder Items (which will be the folder I want)
    2. (Create new variable "path" and drag onto 1., which creates "Get Value of variable)
    3. (ignoring input) Get Specified Finder Item (specifying a blank Pages document)
    4. (accepting input) Copy Finder Item to variable "path"
    The problem with this is that step 2 returns both the desired folder AND the desktop. The result of the entire process, moreover, is that the blank Pages file is created (or rather copied to) the desktop ONLY, and not to the desired folder.
    Anyway, I hope someone can help me with this. It would really speed up my organizing process.
    Wes

    Taking care of true window's properties is often useful
    on run
    try
    tell application "Finder" to set myFolder to (target of the front window) as alias
    on error -- no open folder windows
    set myFolder to path to desktop folder
    end try
    set myNewDoc to my makeNewIworkDoc("Pages", "myNewDocument" & my dateTimeStamp() & ".pages", myFolder as text)
    end run
    --=====
    Creates a new iWork document from Blank.template,
    saves it and returns its pathname.
    example:
    set myNewDoc to my makeNewIworkDoc(theApp, docName, folderPath)
    on makeNewIworkDoc(a, n, d)
    local t, c
    if a is "Pages" then
    set t to ((path to applications folder as text) & "iWork '09:Pages.app:Contents:Resources:Templates:Blank.template:") as alias
    else if a is "Numbers" then
    set t to ((path to applications folder as text) & "iWork '09:Numbers.app:Contents:Resources:Templates:Blank.nmbtemplate:") as alias
    else
    if my parleAnglais(theApp) then
    error "The application “" & a & "“ is not accepted !"
    else
    error "l’application « " & a & " » n’est pas gérée !"
    end if
    end if
    set f to d & n
    tell application a
    set c to count of documents
    open t
    repeat
    if (count of documents) > c then
    exit repeat
    else
    delay 0.1
    end if
    end repeat
    save document 1 in file f
    end tell -- theApp
    return f as alias
    end makeNewIworkDoc
    --=====
    on parleAnglais()
    local z
    try
    tell application "Numbers" to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    on dateTimeStamp()
    return (do shell script "date +P%Y%m%d-%H%M%S")
    end dateTimeStamp
    --=====
    Yvan KOENIG (VALLAURIS, France) vendredi 4 septembre 2009 20:51:02

  • Need to Create Search Help Based on Condtions from one table to another tab

    Hi All,
    I have a table like ZGROUP Which contains the data below
    Filed name Filed Name Filed Name
    ZGROUP ZTYPE ZTEXT
    Entries
    ABC P TEXT FOR
    C P SDFNSDFKLN
    DDDD PSG TEPRTPERERTWERT
    DEF P TEST
    FFFFF PSG
    SEF PS SDFSDFLASLDFNASDLFN
    XYZ PS TESTING
    Whree P is Product , PS- Point of Sales, PSG-Sales Group
    Now i am going to crate another ZPROUDCT TABLE
    FIELDNAME FIELDDESCRITPON
    PRODUCT PROD_DESC
    Entry
    abc pRELATED ENTRY
    My Questions
    1) ZGROUPS table has 3 kinds of data P, PSG, PS type records,
    1) In Table ZPROUDCT , I want to create search help only P records for Table Zproduct of the field Product FROM zGROUPS table
    2) In Table Zsales , I want to create search help only PS records from ZGROUPS table
    3) In Table ZPSG, I want to create search help only PSG records from table ZGROUPS
    is it possible to create search help from One Master Table(ZGROUPS) table to other tables based on conditions.
    Please help me.
    very urgent
    Regards,
    Raju

    if  <condition>
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR <field>
    SELECT <field>
             FROM <table>
             INTO TABLE i_tab
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'                  "function module to provide f4 help to sold-to-party
        EXPORTING
          retfield        = "XXXX"
          dynpprog        = sy-repid
          dynpnr          = sy-dynnr
          dynprofield     = '<field name>'
          value_org       = 'S'
        TABLES
          value_tab       = i_tab
    endif.
    lkike this u can check the condition and selec the data from table and assign it into one internal table and then call the FM it will give the f4 help to particular field
    reward if helpful
    regards,
    Khan.

  • Create "Object" Type based on columns of a table

    Hi Experts
    is it possible to create an Object Type based on columns of a table?
    for example the syntax for creation of type is
    CREATE OR REPLACE TYPE temp_t
    AS OBJECT (ID number, code number)
    can we create a type that is based on columns of an existing table? so that we donot have to write down all the column names in each type as i have to create types based on 100 and above tables :-s
    Please help me out here!
    Best Regards

    You cannot do that Zia, check below code:
    SQL> create or replace type temp_t as object(object_name all_objects.object_name%TYPE);
      2  /
    Warning: Type created with compilation errors.
    SQL> sho err
    Errors for TYPE TEMP_T:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    1/35     PLS-00201: identifier 'ALL_OBJECTS.OBJECT_NAME' must be declared

  • Create paragraph style based on selection

    Is there a way to create a paragraph style based on the selection in the same way the "New Paragraph Style" dialog box does without having to go through ALL of the elements of the style individually?
    Thanks

    I was hoping (even expecting) that this would work:
    if (app.documents.length > 0 &&
        app.selection.length === 1 &&
            app.selection[0].hasOwnProperty("baseline")) {
        var myDoc = app.documents[0];   
        var myPstyle = myDoc.paragraphStyles.add({
            properties : app.selection[0].properties,
            name : "myNewStyle"});
    but the result is very disappointing, particularly with respect to the font details. Maybe you just can't use the properties property as part of an add() method call, because this works pretty well:
    if (app.documents.length > 0 &&
        app.selection.length === 1 &&
            app.selection[0].hasOwnProperty("baseline")) {
        var myDoc = app.documents[0];   
        var myPstyle = myDoc.paragraphStyles.add({name : "myNewStyle"});
        myPstyle.properties = app.selection[0].properties;
    Dave

  • Create a structure based on Selection option field values?

    Hi Guys,
                 can anybody tell me is ther anyway to creat a strucitre after giving the values to selection screen .I have a req where fiscal period is entered based on this i have to create a structure suppose i he give 3 to 8 then i have to create a strucure with with some fields including period3 period4 like that until Period8 so is there anyway tocreate like that or not?
    Thanks,
    Gopi.

    You need an internal table not a structure.  Either count from from the low value to the high value adding a record to the table or select the entries from the Period master table for that selection range.
    Option 1
    REPORT  ZCOUNT.
    tables: t009b.
    select-options:
      s_period   for t009b-poper no-extension.
    data:
      gt_poper type table of poper,
      gs_poper type poper.
    start-of-selection.
      move s_period-low to gs_poper.
      while gs_poper le s_period-high.
         append gs_poper to gt_poper.
         add 1 to gs_poper.
      endwhile.
      loop at gt_poper into gs_poper.
        write:/  gs_poper.
      endloop.
    endloop.
    Option 2
    REPORT  ZCOUNT.
    tables: t009b.
    select-options:
      s_period   for t009b-poper.
    data:
      gt_poper type table of poper,
      gs_poper type poper.
    start-of-selection.
      select poper
        from t009b
        into table gt_poper
        where bdatj = '2007'
         and poper in s_period.
      loop at gt_poper into gs_poper.
        write:/  gs_poper.
      endloop.
    Not sure if t009b is the right table.
    Ta... JR

  • Use Automator to create new subfolders in a selected folder

    This seems like it should be easy to accomplish, but I have had no luck.
    I want to be able to select a folder, and then run an Automator Service to create a specific set of subfolders within the selected folder.
    I am able to set up automator to create the subfolders, but it does so in the folder containing the selected folder.
    Any suggestions on how to accomplish this simple task?

    Which type of variable should I choose? I tried "text" but there's no way to set it to "input"? There are many Variables in the Library.
    Here's how I have things set up now, I thought the "Service receives selected 'folders' in 'Finder'" (at the very top of the workflow area) would pull in the selected folder.
    Thanks!

  • Creating new hierarchy based on existing r/3 hierarchy & loading

    Hi,
    We have an existing hierarchy in BW which we bring in from SAP R/3.
    I want to use the majority of this hierarchy but I need it in a different sequence. If I copy this existing hierarchy and then re-structure it to how I need it, I assume that whenever any changes are made to the existing hierarchy, that these changes won't filter through to the hierarchy I need to create.
    If my assumption is correct, does anyone have any suggestions as to what, if anything, I can do in order to make any changes in the existing hierarchy come through to the new one without any manual intervention.

    Hi Mark,
    The 4th option is to write a code in CMOD and restructure the internal table there itself. In this case you do not need worry about the change in the hierarchy. Please let me know if this helps.
    Rgds,
    Bikas

  • Creating new ODBC connection does not show the tables

    Post Author: reemjacob
    CA Forum: Data Connectivity and SQL
    Hello
    I am creating a new ODBC Connection to SQL Server in Database Expert. Once I created the ODBC when I expand the Database I should be seeing the tables, views and stored procedures. But instead I am only seeing stored procedures. When I right click on the DB and go to options I see that Tables, Views and Stored Procedures are checked. How can I correct this so that I see the Tables and Views?
    Regards
    Reem

    Not an Oracle proble. Not an instant driver problem.
    If the ODBC tool and driver you use, fail to construct the proper SQL to interrogate the very rich Oracle data dictionary.. what is Oracle suppose to do? Fix the software from those vendors for the user? Not going to happen. Get Oracle Raptor instead and use a proper Oracle client.
    Simple test. Run the following SQLs via your ODBC connection.
    To see all your objects in your schema (i.e. the one you logged into via ODBC):
    SELECT * FROM user_objects
    To see a list of schemas:
    SELECT username FROM all_users ORDER BY 1
    To view other schemas' contents:
    SELECT * FROM all_objects
    Also note that historically ODBC has delivered poor performance. I recall many performance tests I've done during the 90's that showed ODBC up to 3x slower and generating more than 4x the network traffic, than native connections. Not too mention using ODBC introduces an additional software layer, which means more moving parts, more complexity, and more failures.
    I have not touched ODBC with the proverbial 10ft pole since - and today, I have even less need to use a clunky software layer like ODBC. And should I be forced to, it will be passthru all the way.

  • Opening a new window on lead select in a table

    Hi,
      I want to open a window on Lead Select ...i have written the below code in the ActionLeadSelect
    ************************Begin Code******************************************************
    message.reportSuccess("came inside LeadSelect");
    IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow("www.yahoo.com","",false);
    message.reportSuccess("came 1");
    window.open();
    message.reportSuccess("came 2");
    ***************************end code********************************************************
    but On selecting a particular row in a table , window is not being opened..but the message I gave are displayed .Can u gimme  a solution
    Thanks,
    Shiny

    Hi, 
         It helped abijeet.Pop Up window is  opened.
    Now, I also tried opening another pop up window. I created a view called 'PopUp'. now.On selecting a row in the table I want to open this window(PopUp) .I tried the below code:
    IWDWindowInfo wInfo =wdComponentAPI.getComponentInfo().findInWindows("PopUp");
        IWDWindow window   =  wdComponentAPI.getWindowManager().createModalWindow(wInfo);
    message.reportSuccess("came 1");
    window.show();
    message.reportSuccess("came 2");
    window.setWindowPosition(WDWindowPos.CENTER);
    window.setWindowSize(100, 100);
    message.reportSuccess("came 3");
    I get the below  exception on executing:
    com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Parameter windowInfo must not be null.
    what else should i set. Can u gimme a solution??
    Thanks,
    Shiny

Maybe you are looking for

  • Want to change a bulleted list to a checkbox list -- HELP

    Why is this so hard? I have a list of software product features, I want the list to have checkboxes rather than bullets so readers will feel urge to check off features when comparing software to other solutions. DOESNT HAVE TO BE INTERACTIVE. Just a

  • Number of Requests per day

    Hi, We are a mid size automobile supplier company and we have implemented EBS with most of the basic modules including but not limited to financial, SCM, Purchasing, HRMS, SSHR, Payroll, Advance Benefits, AME, iSupplier, custom modules in PO, OM, INV

  • MacBook Air won't connect with TimeCapsule

    I recently bought the new Time Capsule and for a while it was happily backing up both my and my wife's MacBook Airs. Then it stopped backing up my wife's computer. On investigation I find my wife's MacBook Air won't connect to the Time Capsule. When

  • Date Profile Position

    Hi, I have added SRV_CUST_BEG to my date profile for a Service Confirmation, via the Interaction Centre. Problem I have is that the field for SRV_CUST_BEG does not appear. Should it/where? Everything looks fine in customising except for the Screen ar

  • Quicktime movies in IE

    Hi When I visit a webpage with a QT movie embedded - for example, the MacOSX Leopard page or the new nano commercial page, the video window persists when i navigate away from that page. I have to close my browser completely to reset. I am using an HP