Sorting blank column in jTable

Hi all,
I am having problem sorting blank columns.
I have already read thru [http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting]
Using setAutoCreateRowSorter works except when sorting blank column as i want all blank column to be sorted to the bottom be it ascending or descending order.
I am using Comparator to do the sorting but how do I know when it is doing ascending or descending?
Edited by: zwseo on Jul 17, 2008 7:25 PM

TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(this.dataTable.getModel());
            Comparator<String> comparator = new Comparator<String>() {
                public int compare(String s1, String s2) {
                    if (s1.compareTo(s2) == 0) { // same string
                        return s1.compareTo(s2);
                    } else {
                        if (s1.trim().equals("") && !s2.trim().equals("")) //string 1 is null
                            //if ascending, return positve
                            return s1.compareTo(s2);
                            //if decending, return negative
                            //return s2.compareTo(s1);
                        else if (!s1.trim().equals("") && s2.trim().equals("")) //string 2 is null
                            //if ascending, return negative
                            return s2.compareTo(s1);
                            //if decending, return positive
                            //return s1.compareTo(s2);
                        else {
                            return s1.compareTo(s2);
            this.dataTable.setRowSorter(sorter);I am not sure whether i am doing this right.... please help me on the comments part... i do not know how to write that if statement.

Similar Messages

  • Programmatically Sorting columns in JTable

    Hi,
    How can I programmatically sort a particular column in JTable without having to click on column header.
    Thanks.

    to sort the desired column w/o click on header
    int columnIndexToSort = 1;
    RowSorter.SortKey sortKey = new RowSorter.SortKey(columnIndexToSort,SortOrder.ASCENDING);
    ArrayList alist = new ArrayList(1);
    alist.add(sortKey);
    ((DefaultRowSorter)table.getRowSorter()).setSortable(columnIndexToSort , true);
    ((DefaultRowSorter)table.getRowSorter()).setSortKeys(alist);
    ((DefaultRowSorter)table.getRowSorter()).sort();expecting dukestars..

  • Sorting Columns in JTable Using Different Comparators

    Is there any way to sort each column in a JTable using different comparators?

    you'll have to write your own tableSorter

  • Serial number column in Jtable

    Apologies for this distraction.
    I read at this forum about a year ago how to add a s/n column in Jtable such that all the nos are automatically updated/adjusted when a row is added/deleted. the count starts from the top down serially and unaffected by sorting.
    pls help!

    thanks a million BaltimoreJohn and especially camickr whose solutions to problems have been most helpful. applying the referenced post, i worked around the problem by resetting the values of the column having the serial number, based on table rowCount every time there is an operation on it(deleting, addition etc)

  • Sort - not columns - but rows in 3.01

    How to sort - not columns - but rows - in 3.01?

    Hi Sune,
    While we all wait for Apple to put this feature back in another update of Numbers 3, try this:
    You want to sort rows 11-14 (as an example). Add a Colour Fill to row 15 as a guide for later.
    Select rows 11-14. Click and *hold* on any Row Reference Tab. You will see the selected rows appear to 'lift'. Drag those rows away from Table 1 to a blank part of the 'canvas':
    and they will form a new table. Sort this table.
    Then select all rows of Table 2, and Copy.
    Click on Table 1. Select the colour filled row where you want to insert (row showing 23 Jun 2013 in this example).
    Menu > Insert > Copied Rows.
    Not as easy as Numbers 2.3 Reorganize Panel, but a workaround.
    If you frequently resort the same rows, consider placing them in their own table.
    Regards,
    Ian.

  • Adding blank column in Oracel Answers OBIEE

    Good morning.
    I am attempting to add a 3 blank columns in OBIEE and then adding a formula to one of the blank columns to do a simple math calculation between 3 other columns. I used "CAST(Null as double)" in my column formula to make it a blank column and not pulll data from the field column that I added.
    This is what I have so far:
    Column1 formula = "Cast (Null as double)"
    Column2 formula = "Cast (Null as double)"
    Column3 formula = "Cast (Null as double)"
    Column4 formula = data already included from the column that I added.
    This is what i'm trying to do:
    Column3 = (Column4 - Column1 + Column2) <----- In excel I would do something like "=D4-E4+F4" (example)
    When I do my SUM function in OBIEE and try to add the columns, it pulls in "Cast(Null as double)" and not the actual column name that I custom edited.
    Any help would be appreciate on how to add a blank column and add a simple calculation formula to calculate data from the blank columns once I export my report to excel.
    Thank you,
    Edited by: 970040 on Nov 7, 2012 8:24 AM

    Thats correct. When I export the report I want to see blank values in the columns. so when I enter data into those blank fields on my excel spreadsheet, I want the totals column to calculate according to my formula specified. My issue is when I specify a null value in my columns in OBIEE, im unable to put a formula to calculate the values in my other columns.
    This is what I have so far in OBIEE:
    Column1 formula = "Cast (Null as double)"
    Column2 formula = "Cast (Null as double)"
    Column3 formula = "Cast (Null as double)"
    Column4 formula = data already included from the column that I added with values.
    This is what I’m trying to do:
    Column3 = (Column4 - Column1 + Column2) <----- In excel I would do something like "=D4-E4+F4" (example)
    How can I add a value to my column so that when I export it to excel, the column fields will have the formula already included such as "=D4-E4+F4" and also each row formula corresponding to the correct Row Number.

  • I am unable to sort multiple columns in a table created in Pages.

    I had been using Appleworks up until I installed Lion and have now switched to iWork. I created a table within a Pages document and am able to sort a single column (using the Table Inspector and choosing Sort from  Edit Rows and Columns) but the Sort option is grayed out when I attempt to sort multiple columns.
    In another post, someone talked about this being a problem if you have merged fields. I do not believe I have done this (to be honest I don't know the function of merging fields).
    This is very frustrating as I was easily able to sort these tables in Appleworks.

    Sharon Anderson wrote:
    Thanks for your quick response! I have been trying that but then found that Numbers would only let me print in landscape view so I had to paste the table back into Pages. Is there a way to print in portrat view (from Numbers?)
    Not so. In the lower left corner of the window, there's an icon that looks like a piece of paper. If you see this:
    you are in Sheet View, or normal, mode. If you see this:
    You are in Print View mode. Now you see the icons for portrait and landscape modes. Click your choice. Then arrange your content to fit the pages as you wish.
    Jerry

  • How to sort a column directly after data is filled into the grid?

    Hello,
    I have a unbound field X, which is filled on fly in the RowLoaded2 column. If I click on the column header, I am able to sort the column.
    I want to sort the column directly, but all attempts have failed.
    I have tried to call in <anchor>_OnUpdate
    <anchor>.bcol.Sort( "X", "ASC") but it does not work as long as the property is not mapped to a Segment field of a bdoc. For this test i just created my property X on the Business Objects behind the tablegrid
    I have used <tablegridcontrol>.sortCol = 2, but it results into a StackOverflowException even for any other column.
    Is there no way to sort the colum in this special kind of situation?
    Regards,
    Andreas

    Hi,
    you have to consider that when loading a tile for the first time always rowloaded2 is fired (several times) and afterwards onload. Maybe rowloaded2 again afterwards. So it should work to sort in onload.
    But when clicking the <back> button in the menue the order of the fired events might be different!
    Do you want to sort by an unbound column which is readonly or is it also editable (see other thread)? In this case things might be much more complicate... Normally another sorting should be done in onsave event but unfortunately you don't save anything as it is unbound...
    Regards,
    Wolfhard

  • Is there any way to do a mass copy and paste of song titles from the "name" column to the "sort name" column? I know it can be done with individual titles but I have over 6,000 titles in my library.

    In iTunes, is there any way to do a mass copy and paste of song titles from the "name" column to the "sort name" column? I know it can be done with individual titles but I have over 6,000 titles in my library.

    Thank you. I have heard of Logic Pro 7, but I have never personally used it. I'm still growing in the world of Composition, and I know that it is something I will be studying in one of my Computer Music classes coming up for my degree. I think it is something I will look into getting once I can justify the price of it. I guess for the time being, I will continue to play and grow in my ability to use and take advantage of GB, and then see what I can do about or with Logic Pro when I'm ready. The thought of spending $1000 for a program is hard to bite, because I've already spent a lot to produce my music, not only electronic music, but also chamber music and so on. I had no idea it would be so expensive to dive deep into the world of composition! lol.
    Finale 2007: $500
    Sibelius 4: $500
    Jam Packs: $400
    Midi Keyboard Interface: $100
    PowerBook: $1700
    Printer for printing scores and analysis: $150
    Logic Pro 7: Oy!
    As you can see it adds up very quickly...that doesn't even include my personal instruments and study materials.
    Thank you for your input, as I haven't really worked much with LP, and therefore didn't know which features are available. I will talk with some of my Composition buddies, and professors and see what they have to say as well, and who knows, I may be able to get the express version through one of them.

  • Sort table columns in a table and context created dinamically

    Hello all,
    I have implemented the table sorting several times in another developments, but now I'm facing a problem.
    I have created the table and context node that I need to sort dinamically (before somebody ask me why, I would say that it's the only way to do that for my current project, there was no possibility of doing that in dessign time). I have implemented the table sorting more or less the same way I would do with a table created in dessing time, but when I run my WD the sorting of columns doesn't work.
    In the wdDoModifyView, I have put the following code:
    if(firstTime){
    IWDAction ordenacion     = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ORDENACION,  null);
    IWDParameters param = ordenacion.getActionParameters();
    param.addParameter("nombreNodo",nombreNodo);
    and in the code of the action
        //@@begin onActionOrdenacion(ServerEvent)
         System.err.println("**** NOMBRE NODO **** "+nombreNodo);
         wdContext.currentContextElement().getTableSorter().sort(wdEvent, wdContext.getChildNode(nombreNodo, IWDNode.LEAD_SELECTION));
        //@@end
    The name of the node ("nombreNodo) it's only correct the first time I click on a column.
    Has anybody implemented the table sorting in a dinamically created table and context node? And how do you do to make it works.
    Thank you very much

    Here is the code
    //Preparamos Navegaciones
    IWDAction abrirProyecto = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ABRIR_PROYECTO, null);
    IWDAction abrirDisp     = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ABRIR_DISPONIBLE,  null);
    //IWDAction ordenacion     = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ORDENACION,  null);
    IWDAction ordenacion=wdThis.wdGetOrdenacionAction();
    IWDParameters param = ordenacion.getActionParameters();
    param.addParameter("nombreNodo",nombreNodo);
    IWDTable table = wdThis.wdGetInformesController().crearTabla(view, nombreNodo, movimientosInfo,new String[]{"Codi Projecte",null,"Nom Projecte", "Import Projecte", "Client", "Increment Disponible futur per facturació no emesa i / o anualitats pendents","Increment Disponible futur per ingressos pendents de cobrar", "Disponible"},new String[]{"10px", null,"10px", "10px","10px","10px","10px","10px"},new IWDAction[]{abrirProyecto,null, null, null, null,null,null,abrirDisp}, -1);
    //ordenar tabla
    wdContext.currentContextElement().setTableSorter(new TableSorter(table, ordenacion,null));
    containerTablasProyecto.addChild(table);
    Edited by: Mireia Romo on May 28, 2009 12:27 PM

  • Hiding a column in jtable made from DefaultTableModel.

    I have made my jtable from DefaultTableModel.
    I want to keep one column in the jtable as hidden storing some data containing neccessary information like the "path of the file"
    which need not be shown to the user.
    Please tell me how I can hide one column in the Jtable.
    please provide siome link or code for the same.
    Tia,
    Sarwa

    dayanandabv wrote:
    [http://search.sun.com/search/onesearch/index.jsp?qt=hide+column%2B+JTable&rfsubcat=&col=developer-forums]
    My thought exactly.
    db

  • Pages:  How can I sort one column of words and not have it affect the other columns?

    How can I sort one column of words and not have it affect the other columns?  I have opened the inspector to the edit columns and rows under Table.  It will sort the column, but then it changes the other colums as well.  I know that if I use Numbers, it will work, but I want to know how to do the same thing in Pages.

    Hi Peter,
    Numbers sorts full rows on values in selected column(s). The technique for sorting a single column is essentially the same as Jerry is describing for Pages tables—separate the (data in the) column to be sorted, sort it, return it to the table.
    In Numbers the actual column may be separated from the original table, sorted, then returned. In Pages, the data must be extracted, sorted, then pasted back in, overwriting the unsorted data (if it was left in the original table).
    iWork tables follow a database model in which each row is a Record, and each column holds a Field within the records.
    As evidenced by the current question (and several similar questions arising in the Numbers community) that model doesn't apply to the way some users, especially some who come in from the MS Excel world, use tables.
    With Excels model—islands of data on a single large table, the ability to sort one or a selected few columns of data makes sense. One 'island' may comprise only cells AA21:AH50. Sorting that small 'table' should be possible without disturbing the rest of rows 21-30, which are probably part of one or more other 'data islands' in the sea that is a MS Excel spreadsheet.
    In Numbers, each of those 'islands' would be a separate Table, and that Table would be sortable without disturbing other Tables in the document.
    Regards,
    Barry

  • How to set different renderers to different cells in same column of JTable?

    Hello Friends,
    I need your help again...
    Does any body knows, how to set different renderer's for different cells of same column in JTable..??
    For ex.
    Col1 Col2 Col3 Col4
    A       A       A      A
    A       A       A      B
    A       A       A      C
    A       A      A       D
    Where A B C D would be different Renderers.  I want set exactly same ,,, ie. one column with different renderer at different cell positions..
    Right now i m setting renderer using statement bellow :
    table.getColumnModel().getColumn(int).setCellRenderer(rederer_Instance);But with this, effect in the last renderer is applicable whole column....
    Can any body help me out ?????????
    please refer this thread for similar kind of discussion...
    http://forums.sun.com/thread.jspa?forumID=57&threadID=571445Thanks
    Suyog

    Please refer to the first reply of [this thread|http://forums.sun.com/thread.jspa?forumID=57&threadID=571445] for the answer. If you have a specific problem implementing it, post you code with a specific question.

  • Layout in sql report gets disturbed in case of blank columns

    Hi All,
    I have an SQL report which runs from a concurrent program.
    Problem is, if there are blank columns in the report then the data shifts to the left.
    As shown in the below table, if column Attribute 4 is null then the data for Error column has shifted to the left. The words Incorrect Data should come under heading Error whereas it comes under Attribute4.
    ASSET_NUMBER_REC ATTRIBUTE_CATEGORY_CODE ATTRIBUTE4 ERROR
    316604 ABCD Incorrect Data
    Can someone help me in correcting the report layout.
    Regards,
    Shruti

    ASSET_NUMBER_REC ATTRIBUTE_CATEGORY_CODE ATTRIBUTE4 ERROR
    316604 ABCD Incorrect Data
    Can someone help me in correcting the report layout.
    Hi
    SQL Report --- Do you mean SQL Query in such case,
    Please use NVL function on all column, which will give you proper place result.

  • Blank Column in Query

    Hi There
    Please advice me how to create a blank column in Query?
    Thanks in advance..
    Regards,
    Chandu.

    Hi
    I don't have any IO's regarding that.I just need create a column with some description then user can fill with data.
    How can i run that?
    Thanks in advance.
    Regards,
    Chandu.

Maybe you are looking for

  • Pixi Plus-Can't Delete PDF or Doc View Items

    I have a long list of items on my PDF list that I can't delete.  I also have a few items on my Doc View which won't delete.  I've tried going the USB route, but nothing shows up for the PDF and I can't find a place for the Doc View.  I've also tried

  • Oracle Application Server 10.2 installation problem: Error in invoking targ

    Hi, I am installing Oracle Application server 10.2 in IBM AIX 6.1 and I encounter this error during the installation.. Error in invoking target "install" of makefile I am in the linking part kindly help me out. thanks...

  • Application deploying problem JDevelopeStudio Edition Version 11.1.1.2.0

    Hi we are using JDeveloperStudio Edition Version 11.1.1.2.0 and facing strange problem on few machines,when we are trying to run the application we are getting error as follows: [11:00:11 AM] #### Deployment incomplete. #### [11:00:11 AM] null #### C

  • Urxvt & scrolling

    Despite serious reading of the manpage and some googling, I cannot figure out how to fix/rebind my scrollback in urxvt . I'm not able to use Shift+PgUp/Down to scroll back/forward in the buffer (or use any other sane shortcut I can find), forcing me

  • Item category 02000 is missing (obligatory in accounting transaction 0200/0

    Dear Guru we tried to post transaction customer with special GL account and Revenue line item with document type DI which is Customer Invoice. The point is users can post it for every month until now they do month-end closing and post the transaction