Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can a JFCTable column heading be clicked in order to arrange the data in according to the header?

How can a JFCTable column heading be clicked in order to arrange the data in according to the header?


Although there is no inbuilt method to manipulate the data in a JFCTable Column the following steps should allow you to work around the issue.

  1. The first step would be to expose the JScrollPane and the JTableHeader classes. These by default are ignored by SilkTest but adding them into the corresponding Javaex.ini file should expose these classes to SilkTest. You need to add these under the [ClassList] section in the aforementioned ini file. It should look something like;


  2. Next you need to add the following winclass into your declaration

    [-] winclass JavaTableHeaderCustomClass : AnyWin
        [ ] tag "[javax.swing.table.JTableHeader]"
        [ ] obj RECT getHeaderRect (int a1)

    This will allow us to use the "built in" Java method getHeaderRect () which is required when it comes to returning the dimensions of the Column Header. You can now go ahead and record a declaration for your Table which should look something like;

    [-] window JavaDialogBox JFCApplication
        [ ] tag "JFC Application"
        [-] CustomWin JavaxSwingJScrollPane
            [ ] msw tag "[javax.swing.JScrollPane]$javax.swing.JScrollPane"
            [-] JavaJFCTable JavaxSwingJTable
                [ ] tag "$javax.swing.JTable"
            [-] JavaTableHeaderCustomClass JavaxSwingTableJTableHeader
                [ ] tag "$javax.swing.table.JTableHeader"
  3. The next part of the solution we need to implement is the actual locating and clicking of the correct header. The following code will cycle through all the headings until the specified "header" is located. It will return the index of the correct column header. In this example we will search for a column header "Header A".
                  [ ] string columnName = "Header A" 
        [ ] // get the total number of table columns
        [ ] int totalColumns = JFCApplication.JavaxSwingJScrollPane.JavaxSwingJTable.getColumnCount ()
        [ ] int indexOfSearchName 
        [ ] int i
        [ ] // loop through the names of each column until we find the one we are looking for
        [-] for (i=0; i

    When we have located the correct column header we can use this index to find the dimensions of the header and click the centre.

    [ ] // get the RECT of the table header within the scrollpane
        [ ] RECT myRect = JFCApplication.JavaxSwingJScrollPane.JavaxSwingTableJTableHeader.getHeaderRect (indexOfSearchName)
        [ ] int x, y
        [ ] 
        [ ] // find the middle point of this RECT
        [ ] x = myRect.xPos + (myRect.xSize / 2)
        [ ] y = myRect.yPos + (myRect.ySize / 2)
        [ ] 
        [ ] // now click in the RECT of the scrollpane
        [ ] JFCApplication.JavaxSwingJScrollPane.Click (1, x, y)

Old KB# 22070


Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:27
Updated by:
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.