JTable - Check box in column header with sorting

Hello
I have 3 problems/questions.
1. When adding sorting to a table with
setAutoCreateRowSorter(true);and you click on a column header, normally a sorting arrow will appear, and indicate in what direction its sorting,
but in the column head with the checkbox, even though the sorting works, the arrow will never appear. Is there anyway to fix this?
2. Is there anyway to get the checkboxes in the table cells to be aligned left (I dont mean the columnheader checkbox, but the ones below)?
3. When you click on the columnheader to either sort or check the checkbox, you will have to wait about a second between each click, or else it won't react and won't sort. sometimes you will have to click twice for it to react. If you click a lot of times fast, then it won't react until you stop for a second, and click again, though it will react only on the first click, but not the secont, third, fourh, and so on, until you stop for a second. Is there anyway to fix this, or atleast make it have a better reaction time?
This is the code for creating the table:
public class Example extends JFrame{
    private Container container;
    private JTable exampleTable;
    public Example(){
        container = getContentPane();
        ExamleTableModel examleTableModel = new ExamleTableModel();
        exampleTable = new JTable(examleTableModel);
        TableColumn tc = exampleTable.getColumnModel().getColumn(0);
        tc.setCellEditor(exampleTable.getDefaultEditor(Boolean.class)); 
        tc.setCellRenderer(exampleTable.getDefaultRenderer(Boolean.class)); 
        tc.setHeaderRenderer(new CheckBoxHeader(new MyItemListener()));
        container.add(new JScrollPane(exampleTable), BorderLayout.SOUTH);
        exampleTable.setAutoCreateRowSorter(true);
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );       
        this.pack();
        setSize(500,500);
        setVisible(true);
    }This is the code for the checkboxheader:
    class MyItemListener implements ItemListener 
            public void itemStateChanged(ItemEvent e) { 
                Object source = e.getSource(); 
                if (source instanceof AbstractButton == false) return; 
                boolean checked = e.getStateChange() == ItemEvent.SELECTED; 
                for(int a = 0, b = exampleTable.getRowCount(); a < b; a++) { 
                    for(int c = 0, d = exampleTable.getRowCount(); c < d; c++) { 
                        if(exampleTable.getColumnName(c).equals("")){
                            exampleTable.setValueAt(new Boolean(checked),a,c);
    class CheckBoxHeader extends JCheckBox 
        implements TableCellRenderer, MouseListener {
        protected CheckBoxHeader rendererComponent; 
        protected int column; 
        protected boolean mousePressed = false; 
        public CheckBoxHeader(ItemListener itemListener) { 
            rendererComponent = this; 
            this.setHorizontalAlignment(JLabel.LEFT);
            rendererComponent.addItemListener(itemListener); 
        public Component getTableCellRendererComponent( 
                JTable table, Object value, 
                boolean isSelected, boolean hasFocus, int row, int column) { 
            if (table != null) { 
                JTableHeader header = table.getTableHeader(); 
                if (header != null) { 
                    rendererComponent.setForeground(header.getForeground()); 
                    rendererComponent.setBackground(header.getBackground()); 
                    rendererComponent.setFont(header.getFont()); 
                    header.addMouseListener(rendererComponent); 
            setColumn(column); 
            rendererComponent.setText("");
            setBorder(UIManager.getBorder("TableHeader.cellBorder")); 
            return rendererComponent; 
        protected void setColumn(int column){this.column = column;} 
        public int getColumn(){return column;} 
        protected void handleClickEvent(MouseEvent e) { 
            if (mousePressed) { 
                mousePressed=false; 
                JTableHeader header = (JTableHeader)(e.getSource()); 
                JTable tableView = header.getTable(); 
                TableColumnModel columnModel = tableView.getColumnModel(); 
                int viewColumn = columnModel.getColumnIndexAtX(e.getX()); 
                int column = tableView.convertColumnIndexToModel(viewColumn); 
                if (viewColumn == this.column && e.getClickCount() == 1 && column != -1) { 
                    doClick(); 
        public void mouseClicked(MouseEvent e) { 
            boolean active=true;
            JTableHeader header = (JTableHeader)(e.getSource()); 
            switch (e.getID()) {
            case MouseEvent.MOUSE_CLICKED:
            case MouseEvent.MOUSE_PRESSED:
            case MouseEvent.MOUSE_RELEASED:
                JTable tableView = header.getTable();
                TableColumnModel columnModel = tableView.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = tableView.convertColumnIndexToModel(viewColumn);
                Rectangle bounds = tableView.getCellRect(-1, column, false);
                if (e.getX() > bounds.x + 16) { // only if one the checkbox
                    if (e.getID() == MouseEvent.MOUSE_CLICKED) {active = false;}
                }else{active=true;}
            if(active){
                handleClickEvent(e); 
                ((JTableHeader)e.getSource()).repaint();   
        public void mousePressed(MouseEvent e){mousePressed = true;} 
        public void mouseReleased(MouseEvent e){} 
        public void mouseEntered(MouseEvent e){} 
        public void mouseExited(MouseEvent e){} 
}If you want the code for the ExamleTableModel, I will post it if you ask (having trouble with the character limit).

What are you supposed to cast it to? I might have tried to cast it to something wrong.
I tried
TableCellRenderer tcr = table.getDefaultRenderer(Boolean.class);
((DefaultTableCellRenderer)tcr).setHorizontalAlignment(SwingConstants.LEFT);and that gave me a ClassCastException. But I might have been trying to cast it to the wrong thing.

Similar Messages

  • Check box als column in a standard table, how to get the selected row

    Dear experts,
    I habe standard tablt with check box as column. Now I want to get the current selected row structure and do some changes. How could I solve this problem? till now I just know to get the structure via lead selection.
    lo_node->get_element().
    lo_element = lo_node->get_static_attributes ( static_attributes = ls_row).
    How could I get the element through check-box in stead of lead selection. Many thanks!

    check this code
    To get the selected row number
    data: lr_element type ref to if_wd_context_element,
              lv_index type i.
      lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT'  ).
      lv_index = lr_element->get_index( ).
    Thanks
    Bala Duvvuri

  • Check box  in ALV Header for selection

    Hi,
    I'm working on ALV in ABAP web dynpro. We have a requirement to check some rows and based on the selection a FM should be executed.
    I've used checkbox in the column for selection. Is there anyway to use a check box (or any element)  in the column header and use that to select all.
    I checked the ALV column header class documentation but didnt find anything that allows UI elements in header.
    Any workaround to tackle this?
    Thank you,
    Vasu

    Hi Thomas,
    I've already done that (in toolbar).  Checking if there is some hidden option that I missed to do this. Looks like there isn't

  • How do I sort songs in the iTunes store?  You used to be able to click on the column header to sort the column (ie Popularity)?

    How do I sort songs in the iTunes store?  You used to be able to click on the column header to sort the column (ie Popularity)?

    It seems this is a "backwards" upgrade from Apple in their iTunes 11 release....like you, I used to use that function in the iTunes store to sort through and decide which song version to purchase.   (For a large returned list of songs...see all...then sort by any of the headers, including Popularity...this functionality is now gone.)  
    The iPad always suffered from this...was never able to sort on those same column headers with an iPad.   It seems, this new iTunes release killed that functionality on the Mac as well.
    Just one of the few things that went wrong with number 11!
    Better luck next time,

  • Putting a check box above column for selection in WD ALV

    Hi,
    Can anyone provide me a code snippet and help me how I can
    provide a check box above column for selection in WD ALV.
    Best Regards
    Sid

    Hi Sid,
    As far as I know we cannot put checkboxes directly above the Column headers.
    You can achieve this functionality in a round above method
    You can create a group of checkboxes above your ALV table with names of  columns to be selected beside each check box and proceed with your further processing.
    Also If you are just looking at which columns you need to select to be shown on the
    ALV output
    data: lr_standard_functions type ref to if_salv_wd_std_functions.
    lr_standard_functions ?= wd_this->r_table.
    lr_standard_functions->set_column_selection_allowed( ' ' ).
    Hope this is of some help.
    Regards,
    Ismail.
    Edited by: Ismail Basha on Jan 23, 2008 1:47 PM
    Edited by: Ismail Basha on Jan 24, 2008 3:23 AM

  • Sort by clicking on the column heade with LIFO

    Good morning!
    I would like to sort by last entry is first (LIFO) in my report.
    To do that, I have to un check in sort:
    Home>Application Builder>Application ***>Page 1>Report Attributes*(Otherwise APEX shows: "Your query can't include an "ORDER BY" clause when having column heading sorting enabled.")*
    When I follow the APEX suggestion, my report lost feature to sort by clicking on the column header.
    I still want to keep sorting ability on any column just by clicking on the column header.
    Thanks in advance,
    Sam

    Sam,
    First remove the order by clause from your query and then try to set the sorting using the sort sequence. Thanks.
    Regards,
    --Manish                                                                                                                                                                                                                                                                                               

  • JTable : column header with subheaders

    I need to create a table that looks like this:
    ======================
    Car....|...PRICE......
    .......|dollars.|euros
    ======================
    camry..|18K.....|17k...
    bmw....|80K.....|76K...
    metro..|22K.....|30K...
    (sorry for lousy "graphics")
    My quesion is about the two-layered "PRICE" column header that has two subheaders for two different currencies.
    What is the best way to approach this?

    So there's no standard feature for that (like in HTML)-- you basically have to implement it all yourself?

  • Selecting multiple rows using column header with checkbox in it.

    Dear All.,
    I am trying to select multiple rows with checkbox in column header but it doesnot works...
    Following is my codel
    <af:table value="#{bindings.xx.collectionModel}"
                          var="row"
                          rows="#{bindings.xx.rangeSize}"
                          emptyText="#{bindings.xx.viewable ? 'No data to display.' : 'Access Denied.'}"
                          fetchSize="#{bindings.xx.rangeSize}"
                          rowBandingInterval="1"
                          filterModel="#{bindings.xx.queryDescriptor}"
                          queryListener="#{bindings.xx.processQuery}"
                          varStatus="vs" partialTriggers="sbcSelectAll sbcChkFlag"
                          selectedRowKeys="#{bindings.xx.collectionModel.selectedRow}"
                          selectionListener="#{bindings.xx.collectionModel.makeCurrent}"
                          rowSelection="none" id="tCdMast" width="400"
                          columnStretching="column:c4" inlineStyle="height:200px;">
                  <af:column sortProperty="ChkFlag" filterable="true"
                             sortable="true"
                             headerText="#{bindings.xx.hints.ChkFlag.label}"
                             id="c2" width="55"
                             inlineStyle="#{row.ChkFlag ? 'background-color:#9CACC9;' : ''}">
                    <af:selectBooleanCheckbox simple="true" value="#{row.ChkFlag}"
                                              selected="#{row.ChkFlag}" id="sbcChkFlag"
                                              autoSubmit="true" immediate="true"/>
                    <f:facet name="header">
                      <af:selectBooleanCheckbox simple="true"
                                                autoSubmit="true"
                                                valueChangeListener="#{xxBean.onTableChkAllCheckChanged}"
                                                id="sbcSelectAll"/>
                    </f:facet>
                  </af:column>
    </af:table>
    Managed Bean
        public void onTableChkAllCheckChanged(ValueChangeEvent valueChangeEvent) {
            Boolean newValue =
                Boolean.valueOf(u.nvlString(valueChangeEvent.getNewValue(),
                                            "false"));
            Boolean oldValue =
                Boolean.valueOf(u.nvlString(valueChangeEvent.getOldValue(),
                                            "false"));
            if (newValue.equals(oldValue))
                return;
            int rowIndex=0;
            ViewObject vo = u.findIterator("xxIterator").getViewObject();
            vo.reset();
            while(vo.hasNext()){
              Row row;
              if(rowIndex==0)
                  row=vo.first();
              else
                  row=vo.next();
                 row.setAttribute("ChkFlag", newValue.booleanValue());
              rowIndex=1;
            u.addPartialTargets(tableDocuments);
        }Please help!!.
    Thanks & Regards,
    Santosh.
    jdeve 11.1.1.4.0

    Can you check this sample in the blog post?
    http://sameh-nassar.blogspot.com/2009/12/use-checkbox-for-selecting-multiple.html
    Thanks,
    Navaneeth

  • Function of the check box in column "title"?

    What is the function of the check box in the "title" column of the music area?
    I cannot see any difference, either or not the check box is ticked. ???

    The check boxes have a variety of uses:
    Unchecked songs will be skipped when playing songs from the library or a selection. They will only play when individually clicked on.
    Smart Playlists have an option that unchecked songs won't appear.
    Unchecked songs will not be burned to CD.
    The iPod has an option to only update checked songs
    iTunes: Understanding the Symbols Next to Songs

  • RichTable dynamic column support with sorting

    I have a table of data that has a list of custom properties which is dynamic. They could be text, integer, etc. I would like to display each custom property as a column in the table with the static list of properties as follows:
    Name Data Date CustomProp1 CustomProp2
    dataname some data 10/10/2010 my prop1 12345
    Since properties are dynamic, my collection for the table does not have a fixed set of columns.
    Before I get too far, has anyone had experience doing this such that the columns can be sorted and modified and are not part of a static list? For example, can I somehow override the sort function or what would I put for sortProperty for the column?
    So far I plan on my table being a collection of my data object, then when defining the columns, use a foreach to get the list of custom columns...for the data, I would call a custom tag function that gets the value for the property / row pair (not sure if this will work or if there's a better way)...however, I'm stuck on sorting for sure.
    Any help appreciated.
    Thanks,
    Kris

    Frank,
    Okay, you confirmed my plan. For displaying the dynamic column data, can I add a hashtable to the table's model as follows, sounds like this could work:
    <af:forEach ...>
    <af:column>
    <af:outputText value="#{tablevar.hashTable[foreachvar]}"> </af:outputText>
    </af:column>
    </af:forEach>
    At least this is what I'm going to try...
    Actually, my first roadblock is what to put into the sortable property or is there a way for me to override and use my own method for sort?:
    <af:column sortable="true" sortProperty="">
    </af:column>
    Thank you,
    Kris
    Edited by: KrisFromOhio on Dec 3, 2008 1:37 PM

  • ALV column header with multiple rows and ALV column header span

    How could I have in an ALV a column header on several lines and/or a column header that spans on multiple columns?
    i.e. I would like to have in an ALV two columns, each with it's own distinct header and additionally another column header for both of the columns, that spans across both columns. How could I program this?

    Hi,
    follow below mentioned code
    SET THE LABEL OF THE COLUMN
    DATA: hr_weeknum TYPE REF TO cl_salv_wd_column_header.
    CALL METHOD lr_weeknum->get_header
    RECEIVING
    value = hr_weeknum.
    CALL METHOD lr_weeknum->set_resizable
    EXPORTING
    value = abap_false.
    hr_weeknum->set_prop_ddic_binding_field(
    property = if_salv_wd_c_ddic_binding=>bind_prop_text
    value = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
    set the text of the column
    CALL METHOD hr_weeknum->set_text
    EXPORTING
    value = 'C Form'.
    Regards,
    Srini.

  • FB3 M3 Beta2- Advanceddatagrid column header multiple sort

    Hello People,
    Before 10-1 when the M3 B2 of FB3 comes out i had normal
    columnheaders with the new beta version there are suddenly multi
    sort functions added to the columnheaders of the advanced datagrid!
    How can i remove those.. i have alot of columns and now is
    the headertext wordwrapping like nuts!
    -Sjoerd

    You can set the property sortExpertMode to "true" in
    AdvancedDataGrid.
    The vertical line in the AdvancedDataGrid Header is not shown
    when sortExpertMode="true".
    Even then, if the headers does not get wordwraped, please
    file a bug here -
    http://bugs.adobe.com/flex
    Thanks,
    Sameer

  • MTP check box when cme integrates with ccm

    I am reading a document abour cme and ccm integration.The following step indicates that we need to check MTP.
    Step 3 Ensure that the CiscoCallManager network uses a media termination point (MTP). The MTP is required to provide DSP resources for transcoding and for sending and receiving G.729 calls to the Cisco CME 3.1 system. All media streams between Cisco CallManager and Cisco CME 3.1 must pass through the MTP because Cisco CME 3.1 does not support transcoding.
    Questions:
    1. So it means that if I use g729 on the wan between cme and ccm, I must check this one?
    2. If I don't need transcode, i can uncheck this box right?
    3. I notice as soon as check the box, call transfer button not work on ccm phone. Is this a bug or supposed to be?
    Thanks

    Restrictions on CME
    * Cisco CallManager must use a media termination point (MTP), intercluster trunk (ICT) mode, and slow start.
    * Codecs on all the VoIP dial peers of the H.450 tandem gateway must be the same.
    * Only one codec type is supported in the VoIP network at a time, and there are only two codec choices: G.711 (A-law or
    mu-law) or G.729.
    * Transcoding is not supported.
    * Codec renegotiation is not supported. For example, if an H.323 call that uses a G.729 codec is received by a Cisco CME system and is forwarded to a voice-mail system that requires a G.711 codec, the codec cannot be renegotiated from G.729 to G.711.

  • Allow users to click on a Column Heading and sort

    Hi All
    I created a master Detail table using the BC4J tags, My users are able to search and return results to the DataTableQueryComponent but the would like to click on the column and sort by it.
    How do I achieve that
    Thank you

    With JSF and the ADF Faces table it's easy and built-in, you can right click the table and in the properties on the third tab you can specify for each column if it is sortable.
    In JSP I think you'll have to call a method that will set the order by for the view object and rexecute the query.

  • Check Box in Header of ALV GRID only............

    Hi Experts,
                   Can anyone help me out... in keeping the Check box at the Header Level.....
    This requirement is in the copy of the standard transaction "ME2N". 
    1. In ME2N when you click on the Chage Layout button of ALV grid
    and choose "Sorting" tabe.
    2. Add any 3 fields say 1. Vendor/Supply plant 2. Purchasing group and 3. Purchasing document in the Sort criteria and choose accending order radio button and check box in the sum .
    3. Now click on the Displayed Column tab and remove the above 3 fields from the Displayed colums and add it column set
    4. Now report shows the heirarchial one in the sorting manner.
    5. I want the Check Boxes at all levels both in the header and the item level.
    When I click on the Header level check box all the item level check box should get checked. When I add the check box in the field catalog I am able to see the check box in the item level only because only item level data appears in the internal table and Header level is displayed based on the ALV grid sorting option and that row records are unknown in the internal table.
    Is there some thing which I can do to get the check box at the header level retaining all the functionality of ME2N and ALV GRID.....
    It would be great help if some one solves me this issue... Points will be awarded.
    Br,
    Laxmi.

    Hi Bharath,
               Thanks for your response. Select ALL already existing... My requirement is not to get the whole report records selected at  particular level all items and header should get selected. Say for example  I have Vendor2 i.e,  vendor 1 and vendor2. So in the Vendor 1 i will have Purchasing group1 , Purchasing document 1 and say 10 items under Purchasing document. say same as like in Vendor2. So if Click on the Vendor1 all the sub items of it have to selected so that I can perform further action only for these items not for the enter items of the report.
    Br,
    Laxmi.

Maybe you are looking for