Last column in JTable detaches from edge of JScroll Pane

i have a JTable in a JScrollPane which is in half of a JSplitPane.
The table has autoResizeMode set to AUTO_RESIZE_OFF to make the horizontal scrollbar appear.
However, when i resize the split pane to make the table bigger, the edge of the last column no longer runs to the edge of the JScrollPane, it detaches.
What i need is for the last column to be able to expand infinitely, but when the split pane size is being reduced, for the columns to disapear off the edge of the scroll pane and the scroll bar to appear. This is a mix of AUTO_RESIZE_OFF and AUTO_RESIZE_LAST_COLUMN.

I too had this problem. I had a method that would set the minimum size of columns based on the data within the table, etc. It seems that when you do anything to set the pref or min size of a column the horizontal scrolling gets all messed up. How I solved the problem is to basically swap the autosize method on the table back and forth whenever the parent component of the table is resized. Some example code follows.
First, add a inner class ComponentListener on the parent component the table is in (a frame in my case, I guess this could be the scroll pane too?):
_myFrame.addComponentListener( new ComponentAdapter()
    public void componentResized(ComponentEvent e)
        _parentResized();
});Now the _parentResized() method that is called by the inner class looks like this:
* Our parent container component was resized, so update how the table's
* columns are layed out.
private void _parentResized()
    TableColumnModel tcm = _table.getColumnModel();
    int colWidth = 0;
    for( int j = 0; j < tcm.getColumnCount(); j++ )
        colWidth += tcm.getColumn( j ).getPreferredWidth();
    // Have to check scroll for width > 0, because the first time this gets
    // called, it is 0, and that will cause the viewport to scale to fit the
    // entire table (which could be bad).  Note that this will get updated
    // if the window is resized as well.
    if( _tableScroll.getWidth() > 0 && colWidth < _tableScroll.getWidth() )
        _table.setAutoResizeMode( JTable.AUTO_RESIZE_ALL_COLUMNS );
    else
        _table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
}What that does is whenever the table's parent component is resized it evaluates the pref width of the whole table, if it's greater than the scrollpane's width, it turns autosizing of columns off (which will make the horiz scrollbar work properly), if it is less than the scrollpane's width, it turns autosizing on. Hackish I know.
You need to make sure to call the _parentResized() method as well whenver you do something else that might cause the pref width of the table to be resized (like you repopulate and calc pref widths, etc.)
Hope this is of some use to you.

Similar Messages

  • 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

  • JTable in JPanel last Column resize clips JTable doesnt repaint JPanel

    I have a JTable in a JPanel, when I drag the last column of the JTableHeader (u can see the column resizing as the text of the Table HeaderColumn moves with the drag) the JTable is outside the JPanel. Only when u click on another component and then click back on the JTableHeader does it repaint.
    I have tried jPanel.revalidate(); in the mouseDragged event of MouseMotionListener on the JTableHeader and all manner or repaints and fireTableStructureChanged. But I dont understand the order of events.
    The last bug to fix!!!
    NB I dont want to use scrollpane as its not necessary and as many tables are synchronized with one table it makes repaints less smooth
    Thanks Paul

    Well, I didn't find an answer but I did find a solution.
    The JPanel is the problem. I use it to help with layout which is not obvious in this example.
    As you can see in the code the JTable is placed in a JScrollPane which is place in a JPanel which is placed in a JTabbedPane.
    If I use Box instead of JPanel the JTable in the JScrollPane in the Box in the TabbedPane in the JFrame resizes correclty.
    So although JPanel is resizable with setSize it does not get resized when it's JFrame gets resized.
    I would still like to know why?
    ////////KBS
    JTabbedPane myTP = new JTabbedPane();
    Box myOne = Box.createHorizontalBox();
    Box myTwo = Box.createHorizontalBox();
    myOne.add(pane);
    myTP.add("One", myOne);
    myTP.add("Two", myTwo);
    ////////KBS

  • Total Last Cell from last row, last column into another table

    What I'm trying to do is create a sum in a final table that will add together all the last cell Sums in the last column, last row from all Ten tables.
    Example of where I want to get the information from:
    I know I could use something like this *=SUM(Table 1 :: K45,Table 2 :: D9)* but in the future I want to be able to add extra rows in the Ten tables and therefore have the final table calculate the last cell without having to manualy change the cell numbers in the Sum.
    Message was edited by: Pongify

    Pongify wrote:
    Your "Bingo" solution worked a treat, now with Ten tables do I have to put the code in the last table cell Ten times changing the table number on each?
    Yes you have, the last table is perfectly unable to guess from which table it must grab datas.
    CAUTION There is an oddity which I call a bug.
    If you rename one of the table from which you grab datas, the two first occurences (in bold) in the formula will be adjusted accordingly but the 3rd one will not (the underlined one).
    =INDIRECT(ADDRESS(ROWS( *Tableau 1* :: A),COLUMNS( *Tableau 1* :: 1:1),,,"_Tableau 1_"))
    My guess is that the designers forgot that this "string" has exactly the same status as the first two occurences. Of course it's reported to Apple but at this time, we have to live with it.
    Here is a slightly modifier formula:
    =INDIRECT(ADDRESS(ROWS(Tableau 1 :: A),COLUMNS(Tableau 1 :: $1:$1),,,"Tableau "&ROW()))
    I replaced 1:1 (in the COLUMNS operand) which was modified during the fill down process by $1:$1 which remains unchanged.
    As I am lazy, I modified the last reference to the tables so it is automatically adjusted during the fill down process (my tables are named Tableau 1 thru Tableau 10).
    Yvan KOENIG (from FRANCE dimanche 6 juillet 2008 16:27:30)

  • Focus should remains in the last column .

    Hi,
    I am using JTable with single row and few columns. When I navigate (tab) from last column it returns to the first column but my requirement is it should remain in the last column itself.
    Thanks in advance.
    Thanks and Regards,
    Shiva

    Okay, that makes sense. However, I modified my code to actually move the lead, and it still didn't work. Curious, I added a pop up window to the code, and I found out that it doesn't get called. The tab key still doesn't do anything. I miss KeyListeners already :(
    Can you spot anything wrong with how I'm doing this?
    InputMap im = _table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tabKey = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    Action tabAction = new AbstractAction(){
                   public void actionPerformed(ActionEvent e){
                        int leadColumn = _table.getColumnModel().getSelectionModel().getLeadSelectionIndex();
                        leadColumn ++;
                        if(leadColumn > 4){
                             leadColumn = 4;;
                        _table.getColumnModel().getSelectionModel().setLeadSelectionIndex(leadColumn);
                        JOptionPane.showMessageDialog(null, "L: " + leadColumn);  //this doesn't happen either
    im.put(tabKey, tabAction);

  • How to get the last column info of the given table

    Hi All,
    I want to get the last column information like :
    column name, datatype of the last column in the given
    table use PL statement. Please help.
    Thanks,
    JP

    SCOTT@orcl SQL> desc emp
    Name                                                  Null?    Type
    EMPNO                                                 NOT NULL NUMBER(4)
    ENAME                                                          VARCHAR2(10)
    JOB                                                            VARCHAR2(9)
    MGR                                                            NUMBER(4)
    HIREDATE                                                       DATE
    SAL                                                            NUMBER(7,2)
    COMM                                                           NUMBER(7,2)
    DEPTNO                                                         NUMBER(2)
    SCOTT@orcl SQL> select column_name, data_type from user_tab_columns
      2  where table_name = 'EMP'
      3  and column_id = (select max(column_id) from user_tab_columns
      4  where table_name = 'EMP');
    COLUMN_NAME                    DATA_TYPE
    DEPTNO                         NUMBER
    SCOTT@orcl SQL>                                                                      

  • Error importing text file into SQL Server when last column is null

    Hello all. Happy holidays!
    I'm trying to import a text file into a SQL Server table, and I get the error below when it gets to a row (row 264) that has null in the last column. I'm guessing the null jumbles up the delimiters somehow. The nulls are not errors, and I need to import
    them into the table with the rest of the rows. Any idea how I can do that?
    Thanks!
    [Flat File Source [1]] Error: Data conversion failed. The data conversion for column "XYZ" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
    [Flat File Source [1]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "output column "XYZ" (178)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "XYZ"
    (178)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
    [Flat File Source [1]] Error: An error occurred while processing file "ABC.txt" on data row 264.
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "Flat File Source" (1) returned error code 0xC0202092.  The component returned a failure code when the pipeline engine called PrimeOutput().
    The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
    WeeLass

    Hi WeeLass,
    The error that” Data conversion failed. The data conversion for column "XYZ" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".” is generally error message, and the error indicates
    that there is data type mismatch issue between the input columns and the output columns.
    Based on your description, the issue is that you trying to convert a column contains empty value from string to integer data type for the output column "XYZ" in Flat File Source [1]. Please note that we cannot type an empty value as integer data
    type column value, so the error occurs.
    To fix this issue, just as you did, we should convert the data type for the output column "XYZ" in Flat File Source [1] back to DT_WSTR or DT_STR, then use a derived column task to replace the current column (UBPKE542). But the expression should
    be like below:
    LEN(TRIM(UBPKE542)) > 0 ? (DT_I8)UBPKE542 : NULL(DT_I8)
    In this way, the data type of the column in SQL table would be int, and the empty value would be replaced with NULL.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Default Carriage return in the last column when data is downloaded to Excel

    Problem:
    When you download data into Excel and if the last column of your excel is a numeric field, XMLP will add a carriage return (special character) to your numeric field. This feild will be considered as character field by excel.
    Work Around:
    When you build the template, create an empty column as your last column and leave E (or end-for-each) in that empty column.
    Note:
    If the last column is a character column then you do not have to do this.

    I originally had that END:VCARD without any carriage return.
    But I still get an extra carriage return at the end when the JSP renders to VCF
    I'm using Tomcat running on Linux.
    I found this, article which implies (but does not explicitly say) JSP in general adds a newline to the last line:
    http://www.caucho.com/resin-3.0/jsp/faq.xtp (But its not tomcat either, so maybe this info is irrelevant).
    Edited by: shogo2040 on Dec 22, 2008 3:31 PM - changed rendered to VCF from rendered to JSP

  • 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.

  • ALV - Excel download Date field sits in the last Column

    Hi,
    I have custom ALV grid report using OOp . From the report i am exporting the results to an EXCEL, but the date columns in the report sits as last column the exported excel.
    Any idea ?
    Thanks
    aRs

    That is the default functionality of the ALV grid, it collects all the similar data types together and then donwloads the data.
    If you don't want that, you will have write code yourself and download the data
    Regards,
    Ravi
    Note - Please mark all the helpful answers

  • Ragged right with Flat file in SSIS for last column

    When I am importing from Flat file to OLEDB using DATA flow in SSIS,
    It has fixed length  for each column
    but last column had length of 20
    So I used for last column as {LF} and input width 0 & output width 20
    but facing problem of last column has showing more data in preview so I am missing some some records
    May I get any  solution
    Thanks

    Hi Madhu,
    I totally agree with Visakh. If your row delimiter is {CR}{LF}, you need to consider the two placeholders for the delimiter when defining the column length, that is to say you need to set the length of the last column to 22.
    Regards,
    Mike Yin
    TechNet Community Support

  • Keyboard Access For a Column in JTable with default editor as JComboBox

    I want to get Key board access for a column in JTable.
    The user should be able to select from a drop down list for the column with default
    editor set as JComboBox.
    Presently,it works fine with mouse,also I am able to focus it with Keyboard using
    ALT+Up keys,but how to make drop down list appear.
    Plz help,it's urgent.
    Thanks in Advance

    Hi,
    In addition to setting DO_SUM = 'X' you need to specify function in H_FTYPE field. It should be set to 'AVG' in your case.
    ls_fielcat-do_sum = 'X'.
    ls_fieldcat-h_ftype = 'AVG.

  • Edge animation works in browser preview from edge and muse but not in chrome when published

    I have an Edge animation that worked fine in Chrome, Safari and IE.
    The last time I published my Muse site (To BC) again (since update to CC2014) it no longer worked in Chrome!
    Preview in browser (Chrome) from edge works, preview in browser (Chrome) from Muse works, publish and it doesn't work in Chrome (but does in Safari and IE).
    Have been trawling for possibilities but I'm not that web techy! Any help would be appreciated

    I don't remember specifically what fixed it at all as I'd done all of the following:
    Removed Muse and Edge and prefs
    Updated Muse and Edge
    trashed cache in Chrome
    copied the contents of the Edge project / stage into a new project and saved as cc2014 version
    re-published the whole site from Muse
    After many attempts it started working again but I can't say that it was one thing in particular - sorry about that.

  • Remove the last chr(13) & chr(10) from a string

    Hello, all.
    I'm trying to get confirmation files to upload to Amazon for their "Charge When Ship" program.  I've got the file creating as it should be with one minor exception.
    I'm setting a variable, giving it the header column information and ending that with chr(13) & chr(10); then I'm looping through a query to add the information, each iteration tacks chr(13) & chr(10) to the end of it; then I'm taking that variable and writing the data to a file using CFFILE.
    But I think that the last chr(13) & chr(10) is causing Amazon servers to think there's one more line of information than there really is, and it's erroring.
    Can anyone tell me how to remove that last chr(13) & chr(10) from the variable before writing it to file?
    Thanks,
    ^_^

    giving it the header column information and ending that with chr(13) & chr(10); then I'm looping through a query to add the information, each iteration tacks chr(13) & chr(10) to the end of it; then I'm taking that variable and writing the data to a file using CFFILE.
    Trim() the variable or change the code so it does not generate an extra new line.
    Since your content has a header, place the new line characters at the beginining of each query iteration.
    #headerColumnsHere#  <!--- notice there is no new line after the column header  information --->
    <cfouput query="yourQuery">#chr(13)##chr(10)# #ColumnA##ColumnB#...etcetera...</cfoutput>

  • BUG JSF h:dataTable with JDBC ResultSet - only last column is updated

    I tried to create updatable h:dataTable tag with three h:inputText columns with JDBC ResultSet as data source. But what ever I did I have seceded to update only the last column in h:dataTable tag.
    My JSF page is:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page contentType="text/html;charset=windows-1250"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <f:view>
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=windows-1250"/>
    <title>Stevan</title>
    </head>
    <body><h:form>
    <p>
    <h:messages/>
    </p>
    <p>
    <h:dataTable value="#{tabela.people}" var = "record">
    <h:column>
    <f:facet name="header">
    <h:outputText value="PIN"/>
    </f:facet>
    <h:inputText value="#{record.PIN}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Surname"/>
    </f:facet>
    <h:inputText value="#{record.SURNAME}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Name"/>
    </f:facet>
    <h:inputText value="#{record.NAME}"/>
    </h:column>
    </h:dataTable>
    </p>
    <h:commandButton value="Submit"/>
    </h:form></body>
    </html>
    </f:view>
    My java been is:
    package com.steva;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class tabela {
    private Connection conn;
    private ResultSet resultSet;
    public tabela() throws SQLException, ClassNotFoundException {
    Statement stmt;
    Class.forName("oracle.jdbc.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "hr", "hr");
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    resultSet = stmt.executeQuery("SELECT PIN, SURNAME, NAME FROM PERSON");
    public ResultSet getPeople() {
    return resultSet;
    I have instaled “Oracle Database 10g Express Edition Release 10.2.0.1.0” – product on my PC localy. I have enabled HR schema and I have instaled and pupulated with sample data folloving table:
    CREATE TABLE "PERSON"
    (     "PIN" VARCHAR2(20) NOT NULL ENABLE,
         "SURNAME" VARCHAR2(30),
         "NAME" VARCHAR2(30),
         CONSTRAINT "PERSON_PK" PRIMARY KEY ("PIN") ENABLE
    I have:
    Windows XP SP2
    Oracle JDeveloper Studio Edition Version 10.1.3.1.0.3894
    I am not shure why this works in that way, but I think that this is a BUG
    Thanks in advance.

    Hi,
    I am sorry because of formatting but while I am entering text looks fine but in preview it is all scrambled. I was looking on the Web for similar problems and I did not find anything similar. Its very simple sample and I could not believe that the problem is in SUN JSF library. I was thinking that problem is in some ResultSet parameter or in some specific Oracle implementation of JDBC thin driver. I did not try this sample on any other platform, database or programming tool. I am new in Java and JSF and I have some experience only with JDeveloper.
    Java been(session scope):
    package com.steva;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class tabela {
    private Connection conn;
    private ResultSet resultSet;
    public tabela() throws SQLException, ClassNotFoundException {
    Statement stmt;
    Class.forName("oracle.jdbc.OracleDriver");
    conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@localhost:1521:xe", "hr", "hr");
    stmt = conn.createStatement
    (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    resultSet = stmt.executeQuery("SELECT PIN, SURNAME, NAME FROM PERSON");
    public ResultSet getZaposleni() {
    return resultSet;
    JSF Page:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page contentType="text/html;charset=windows-1250"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <f:view>
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=windows-1250"/>
    <title>Stevan</title>
    </head>
    <body><h:form>
    <p>
    <h:messages/>
    </p>
    <p>
    <h:dataTable value="#{tabela.zaposleni}" var = "record">
    <h:column>
    <f:facet name="header">
    <h:outputText value="PIN"/>
    </f:facet>
    <h:inputText value="#{record.PIN}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Surname"/>
    </f:facet>
    <h:inputText value="#{record.SURNAME}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Name"/>
    </f:facet>
    <h:inputText value="#{record.NAME}"/>
    </h:column>
    </h:dataTable>
    </p>
    <h:commandButton value="Submit"/>
    </h:form></body>
    </html>
    </f:view>

Maybe you are looking for