Clicking on table header

I am working with Jtable and want when i click on header that should behave like push button, i mean on clicking that should be in push state and looks different from other header cell.
any idea????

Take a look here:
http://www.codeguru.com/java/articles/218.shtml

Similar Messages

  • Clicking the table header column programmatically

    Hi
    For sorting of the JTable I've used the TableSorter API provided in this site. What I need to do is by clicking on another panel the panel containing the JTable should be displayed sorting the respective column. So what I need to do is click the table header column programmatically. Do you know how can I do that.
    Thanx.

    Take a look at setSortingStatus function in TableSorter.
    If you want ascending sort just call:
    setSortingStatus(columnIndex, 1);This is the code executed when you press table header, it might give you some more insight:public void mouseClicked(MouseEvent e) {
                JTableHeader h = (JTableHeader) e.getSource();
                TableColumnModel columnModel = h.getColumnModel();
                int viewColumn = columnModel.getColumnIndexAtX(e.getX());
                int column = columnModel.getColumn(viewColumn).getModelIndex();
                if (column != -1) {
                    int status = getSortingStatus(column);
                    if (!e.isControlDown()) {
                        cancelSorting();
                    // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                    // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                    status = status + (e.isShiftDown() ? -1 : 1);
                    status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}
                    setSortingStatus(column, status);
            }

  • Clicking on table header throws exception

    I'm using Windows Look and Feel. I made a table and applied the custom renderer to the table header. When I click the table header it throws a NullPointerException relating to the plaf.
    javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler.mouseClicked(Unknown Source)+
    Anybody any Idea. Adding the mouse Listener solves this problem but I dont want to use the listeners just for that reason.

    Take a look here:
    http://www.codeguru.com/java/articles/218.shtml

  • Programatically click the table header?

    hello
    how do you programatically click the table header? i have some panels in a table...there is a button in each one that says "remove" to remove that panel from the table. when i tablemodel.removeRow(thisRow), it sorta does: the row is gone, the overall count is reduced, but it displays wrong until i click on the table header..
    for example..if it lists job 1, 2, 3, 4, and 5. if i delete job #2. 1, 2, 4, 5 are left. when i click on the header it shows: 1, 3, 4, 5 as it should. any query i make to what is there before the header shows the same thing: 1, 2, 4, 5. wierd eh? so i need a way to click on that header programatically. i know its a hack, but i cant figure out why its not deleting the right oen for that little time before the header-click.

    When you say table, I'm assuming you mean JTable since you're using
    a TableModel.
    You might try just encouraging the table to redraw itself as that's
    probably what is happening when you click the header. I've noticed
    that is often required when removing components. Anyways, I'd try
    experimenting with calls to
    repaint() and/or
    validate() or invalidate()
    on the JTable or its parent and see what happens.
    : jay

  • Right click on Table header

    Hi,
    Is there any way to capture the right click on the table header of JTable? Can anyone tell me the way to do this.
    Thanks and Regards,
    R.Vishnu Varadhan.

    Thanks for the help.
    Its working.
    Regards,
    R.Vishnu Varadhan.

  • JTable - Clicking table header

    How do I call a JOptionPane or even a JFrame when clicking the table header?

    Thanks Sergio, it helped me but still I can't make event recognize which column was clicked. It seems to be a hard task since I can click a header column without having a column selected, otherwise I could get the column by getColumnName(getSelectedColumn()).
    Do you hv any idea about solving this problem?

  • Getting acess to TableView table header

    Hi,
    How can I get access to the TableView table headers? I want to attach mouse listeners to them so that I can get a call back anytime a user mouse clicks a table header.
    Thanks in advance, best regards,

    You could call:
    tableView.lookupAll(".table-view .column-header .label")after the table has been displayed on a Stage, but the lookup solution seems even uglier than the setGraphic one.

  • How to add the Row count(number of rows in table)  in  the table header?

    Hi,
    I'm having a table. This table is viewed when i click on a search button.
    <b>On the table header it should dynamically display the number of rows in the table, i.e., the row count.</b>
    How to do this? could any one explain me with the detailed procedure to achieve this.
    Thanks & Regards,
    Suresh

    If you want to show a localized text in the table header, you should use the <b>Message Pool</b> to create a (parameterized) message "tableHeaderText" like "There are table entries".
    Next, create a context attribute "tableHeaderText" of type "string" and bind the "text" property of the table header Caption UI element to this attribute.
    Whenever the table data has changed (e.g. at the end of the supply function for the table's data source node), update the header text:
    int numRows = wdContext.node<TableDataSourceNode>().size();
    String text = wdComponentAPI.getTextAccessor().getText
      IMessage<ComponentName>.TABLE_HEADER_TEXT,
      new Object[] { String.valueOf(numRows) }
    wdContext.currentContextElement().setTableHeaderText(text);
    Maybe you want to provide a separate message for the case that there are no entries.
    Alternatively, you can make the attribute calculated and return the header text in the attribute getter.
    Armin

  • af:table header shows link pointer?

    Hi all,
    I have an <af:table> with no selection, sorting, etc. abilities (I've got a CommandButton in the footer, but other than that it's for display purposes only).
    For some reason, hovering over the table header turns the curser into a "link"-style cursor (default in IE is a hand; you know the one I mean). The facet just contains an outputText; there's no link in sight (and indeed, clicking on the header does nothing). I've been looking at the skinning selectors, but I'm not quite sure how to fix this.
    Thoughts?
    Thanks much,
    Avrom

    Hi Frank,
    It may have something to do with the fact that my table has no column headers. The following code (against a standard HR BC project) produces a table in 10.1.3.2 (and 10.1.3.0; don't have 10.1.3.1) that shows this effect:
    <af:table value="#{bindings.DepartmentsView1.collectionModel}"
                  var="row" rows="#{bindings.DepartmentsView1.rangeSize}"
                  first="#{bindings.DepartmentsView1.rangeStart}"
                  emptyText="#{bindings.DepartmentsView1.viewable ? 'No rows yet.' : 'Access Denied.'}">
        <af:column >
            <af:outputText value="#{row.DepartmentId}">
                <f:convertNumber groupingUsed="false"
                                     pattern="#{bindings.DepartmentsView1.formats.DepartmentId}"/>
            </af:outputText>
        </af:column>
        <af:column >
            <af:outputText value="#{row.DepartmentName}"/>
        </af:column>
        <f:facet name="header">
            <af:outputText value="Departments" />
        </f:facet>
    </af:table>[Edit: Any further word on this? Column headers aren't supposed to be a required part of a table, are they?]
    Message was edited by:
    Avrom

  • Add a Button in a table header Webdynpro

    Hi all,
    how can'i add a button in a table header ? and how/where schould be implemented?
    thank you all

    Hi,
    If you want to create Some custom buttons in ALV, you need to write some coding.
    Please go through this...
    ALV with user-defined buttons on toolbar in wd abap
    Re: Adding custom button in standard toolbar in ALV
    If you want to create button is table toolbar. steps :
    1. create TABLE UI Element in view - go to ROOT UI ELEMENT CONTAINER( right side here you find inserted Table ) - Right click on that ->you fined one option INSERT TOOLBAR, click this-> it will insert Toolbar again right click on this tool bar-> You wil find insert
    toolbar element->select Toolbar button. It will insert toolbar and buttons.
    Cheers,
    Kris.

  • Set image in Table Header

    Hi,
    Is it possible to set a image in table header?
    I am using EP 6 NWDS 2.0.9
    Regards,
    Vaibhav

    Create a table, and insert the header.In header properties"imageAlt" and "imageSource" options is there,
    u can give the image name like image.jpg,go to ur application folder,src>mimes>Components and save it the pictures for the same name, deploy it,it's work fine
    Hi,
    Do the following steps:
    1. Go to the layout of the view hving the table.
    2. Select the table from outline and do right click to add table header.
    3. Go through the propertiess of table header and find out imagesource property from the list.
    4. specify the name of image in the imagesource property.
    5. Now go to navigator and expand the structure of your project.
    6. Go to src->mimes->Components...
    7. save the image in the same folder.
    regards,
    amit bagati

  • Shading in Smartform Table Header

    Hi Experts,
    In my smartform I need to provide a gray shading in Header and in few partivular fields in Footer, like, Total.
    Whenever I am trying to select any Text field in the Headerline and in the output option trying to increase the saturation  percentage it is showing "Boxes/Shadings are not allowed within a table".
    Please let me know in details how to achieve this.
    Thanks.
    Anirban.

    Hai,
    In that case you create one more linetype same as what you have now (Eg. Ltype1 and Ltype2 with same columns). Use Ltype1 for Header and Ltype2 for Main area. Now Double click on Table and select "Table" tab. Select all the columns in the Ltype1 with selecting "Draw Lines and Columns" tool from toolbar and give the shading color then activate it. It will work for sure. If you have any queries revert back.
    -Prabu S

  • Html link not visible as table header in jsp

    Hi,
    I am not sure if this question belongs to JSP forum, since it's happening in JSP page I am posting it here.
    I am seeing this strange problem, in my JSP page all the link are looking fine except some links in Table header. Here is the code snippet:
    <th align="left" width="30%"><html:link action="/myAction.do?sortBy=org&all=${param.all}">Organization Name</html:link></th>
    ENV is struts, jstl, html.
    Now the problem is the text Organization Name is not visible, although it's there and I can click it. If I click and drag mouse over it I can see it.
    Also if I put this link anywhere else e.g. <TD> I can see it.
    I am not sure why it's happening.
    Please help me.
    Abhishek

    Sounds like a style issue - is it the same colour as the background for some reason?
    What styles have you got applied to your <th> columns? The text in them?
    Are you using css?

  • JCheckBox in table header

    Hi,
    I have a JTable, and I would like to put a JCheckBox in one of the columns table headers. I have searched the forums, and I believe I need to have an editor and renderer (i think)...and I have seen links that ref. examples (such as http://www2.gol.com/users/tame/swing/examples/JTableExamples9.html but they don't work anymore.
    can someone help explain how I would put a checkbox in the header? I understand the renderers and editors (for the most part)...but how do i put them on table header??
    thanks

    Here is what I have now....but if i click semi-quickly on the column header...its like it doesn't catch the event in time. I can click on a regular checkbox as fast as I want, and it obviously catches my clicks..b/c i can see it check/uncheck over and over. Is there some way to make this work better, act smoother?
    public class MyCheckBoxHeader extends JCheckBox implements TableCellRenderer, MouseListener {
        private boolean mouseClicked;
        private int currentColumn;
        public MyCheckBoxHeader(JTable table) {
            setHorizontalAlignment(SwingConstants.CENTER);
            JTableHeader tableHeader = table.getTableHeader();
            setBackground(tableHeader.getBackground());
            setForeground(tableHeader.getForeground());
            tableHeader.addMouseListener(this);
        /* (non-Javadoc)
         * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
        public Component getTableCellRendererComponent(
                JTable table,
                Object value,
                boolean isSelected,
                boolean hasFocus,
                int row,
                int column) {
            currentColumn = column;
            return this;
         * Had to implement this so the cell would have the same border
         * as the rest of the JTableHeader cells
        /* (non-Javadoc)
         * @see javax.swing.JComponent#paintBorder(java.awt.Graphics)
        protected void paintBorder(Graphics g) {
            g.setColor(Color.WHITE);
            // top
            g.drawLine(0, 0, getWidth(), 0);
            // left
            g.drawLine(0, 0, 0, getHeight());
            g.setColor(Color.BLACK);
            // right
            g.fillRect(getWidth() - 1, 0, 2, getHeight());
            // bottom
            g.fillRect(0, getHeight() - 1, getWidth(), getHeight());
         * Calls doClick(), because the CheckBox doesn't receive any
         * mouseevents itself. (because it is in a CellRendererPane).
       protected void handleClickEvent(MouseEvent e) {
           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 == currentColumn && e.getClickCount() == 1) {
               doClick();
               repaint();
               int rowCount = tableView.getRowCount();
               for (int i = 0; i < rowCount; i++) {
                   tableView.getModel().setValueAt(new Boolean(isSelected()), i, 0);
       public void mouseClicked(MouseEvent e) {
           handleClickEvent(e);
           // repaint the header to make sure the check is shown in the checkbox
           ((JTableHeader)e.getSource()).revalidate();
       public void mousePressed(MouseEvent e) {
       public void mouseReleased(MouseEvent e) {
       public void mouseEntered(MouseEvent e) {
           setCursor(Cursor.getDefaultCursor());
       public void mouseExited(MouseEvent e) {
    }any suggestions would be helpful...thanks

  • Table header cell dividers

    Is there a way to have to make the cells divider lines in a table header be a custom thickness. with different thicknesses on different pages. I am thinking there is no way to do this inside of FM 8. And would that be changed in the read and write or the dtd.

    Hi Frank,
    There's a somewhat more complicated way that has some advantage if you don't mind the work. This solution is to place PDF images of the titles in the header cells as Background Fill Images. The main advantage over a grouped text box is that the background fill image will track the particular cell exactly, even if rows and columns are added or deleted or resized, including the one that the image is in.
    Start with your title in a text box that "just fits".
    Click off the box and then click once back on the box, such that the handles are showing but the text is not selected.
    Command-C
    Switch to Preview.app and Command-N. You now have converted your title to a PDF.
    Still in Preview, Command-C to copy the PDF
    Switch to Pages, Select the Cell, Command-V to set the PDF into the background.
    Set the justification to centered, both vertically and horizontally for the best tracking.
    As far as the rotation goes, you can rotate the Text Box before you convert it, or you can rotate the PDF before inserting into the cell. It doesn't matter.
    Regards,
    Jerry

Maybe you are looking for

  • SL extract structure change

    Hello, I have a SL Data Source from the type 3fi_sl_xx_si. The question is that if one of the fields in the SL will be changed from char 10 into char 3 will the extraction fail? I mean will i have to generate the extraction strutre again and create i

  • Can't use PayPal Credit on eBay.

    I noticed that I have $506 in PayPal Credit in my account. I tried to buy something on eBay and it said that it couldn't authorize my payment. I also tried to buy something on a different site and got rejected. Why is it showing $506 on the main page

  • How to install printer which is not listed in the software list

    I just bought Canon MX372 and I am having a hard time installing it. I have installed the software that came with it and yet I can't add it as printer? It is always giving me a msg to update the software and when I accept to update it takes a minute

  • Simulate a Robot in a 3D Scene

    Hello everybody, I'm trying to Simulate a Robot in a 3D scene using meshes, objects and heritage. Up to now, I can load a 2D .png Plane and a .stl Robot in the same scene and move the plane across the scene to simulate a robot motion. What I should d

  • Macbook with bad display and an external monitor

    Hello, Since the Macbook's display is broken and unusable I thought I might still be able to use it as a desktop connected to an external monitor. The monitor is an Insignia 19" and I'm getting a "mode not supported" error. I've tried many different