JTable resize of last column

I've got a table with 2 columns, the tabel is inside a scroll pane. I want the first table column to be of fixed size and the second column to take up all of the viewports remaining width.
I've setAutoResizeMode(JTable.AUTO_RESIZE_OFF) and getColumnModel().getColumn(0).setWidth(0), however, what method should I employ to determine resize, determine column 1's desired width based on the viewports width and set column 1's width?
Thanks in advance,
Jas

The only thing I can think is that because there is no "NEXT COLUMN" to the one you are trying to resize it throws the ArrayIndexOutOfBoundsException. If you have 4 columns and you tell it to resize next column, and then you try to resize the right side of the 4 column it is trying to resize the next column, column 5, which does not exist and therefore throws the exception.

Similar Messages

  • 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

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

  • JTable:  resizing all columns as 1 column resizes

    I have a JTable with 480 columns inside of a JScrollPane (AUTO_RESIZE_ALL_COLUMNS needs to be off for the JTABLE to display correctly in the JScrollPane). When the user resizes one column I would like the rest of the columns to resize too, so that the column widths of each column are equal.
    Thank you in advance,
    Brent

    [...] I
    I have the JScrollPane listening to a histogram of the
    balances so the user can click on a month in the
    histogram and the JScrollPane (actually JViewport)
    will move to display the appropriate column in the
    JTable. If the column sizes are not uniform then I
    cannot be sure that I'm moving the JViewport to
    display the correct JTable column(s).
    I thing the GUI is a great design for what must be
    done. And thank you for your help and comments.That still sounds pretty klunky. I don't see any user navigating around a 480 column table. They click in your histogram to go to a column, they click somewhere or do keyboard navigation and the display scrolls them a few columns/rows away... they are now lost in a sea of cells and have to go back to the histogram again to try and get back, etc. Having delt with similar situations, there are better ways. Read the last two days dilbert cartoons carefully. :-)
    But anyway...
    You don't have to have all the columns the same width to make a column visible in the viewport. You can just get the appropriate column's rect by either of these methods:Rectangle r = myTable.getTableHeader().getHeaderRect( col );
    Rectangle r = myTable.getCellRect( row, col, true );And then tell the viewport to make sure that rect is visible:myViewport.scrollRectToVisible( r );Much easier than hacking around with custom column resizing logic.

  • Finder in column view has no expander divider on the last column

    I deal with a lot of graphics on my computer and I have a lot of subfolders. While in finder in column view there is no expanding divider for the last column when it is showing a graphic. When I first open a photo or graphic in finder the last column shows the graphic smaller than regular size. In SL there was a column divider to expand only that last column so I could make the graphic larger to see it better. Now in Lion there is no divider on the right side of that last column to expand the last column where the grahic is showing. In order for it to finally expand I have to drag the right side of the Finder window all the way across my display until the bottom slider bar disappears and then that last column will expand. This is frustrating having to have my Finder all across my display just to get the graphic larger.
    Is there a way to get an expander divider to show up for the last column when viewing a graphic in column view? I know I can click on the "eye" icon to see it, but the column view will expand the graphic larger than 100% so I can see more details.
    Thanks for any and all help.
    Connie

    Yes, that is how my whole finder window expands across my display until the bottom slider bar disappears....then and only then does the last column expand. I have to have open as many as 8 columns to get to my graphic. Keeping the Finder window to a smaller size and using the bottom slide bar to navigate to the far right column is nice, but all I want is that far right column where my graphic is showing to expand so I can see it better.
    Thanks but what you suggest only resizes the whole Finder window until it can expand no further, then the last column expands the graphic. But then my whole display is a huge Finder window.

  • JTable resizing VS Horizontal scrollbar

    Heila',
    I have to show the content of a text file in a JTable; the JTable has 2 columns: the first contains the line number and the second column contains the text of the line.
    In order to allow the user to view and scroll the whole text line I added an horizontal scrollbar to the JTable.
    Here is the relevant code:
    gridVis.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JPanGriglia = new JScrollPane(gridVis, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JPanGriglia.getViewport().putClientProperty("EnableWindowBlit", Boolean.TRUE);     
    The problem is that if I set the AutoResizeMode to JTable.AUTO_RESIZE_OFF then I can see the horz scrollbar but when I resize the JFrame containing the JTable the JTable doesn't resize itself.
    Viceversa if I comment the statement:
    gridVis.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    then the JTable resizes correctly but the scrollbar disappears.
    Does exists the way to obtain both this features ?(correct resizing AND horizontal scroll bar)
    Thanks
    Ciao

    Try overriding getScrollableTracksViewportWidth() in JTable. The method returns a boolean value indicating whether the table should resize when its viewport is resized. If you setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS) and add a check to getScrollableTracksViewportWidth() such that it returns true only if viewport.getExtentSize().width is greater than some minimum width, then your table will resize automatically unless it is scaled below the minimum width, in which case a scrollbar will appear. If you're going to do this you'll need your JTable subclass to store a pointer to its scroll pane's viewport so it can get the extent size.

  • Resizing a particular column in a table

    Well, I know that my topic may seem stupid, but I can't find a way to resize the first column of my TreeTable. Here is what I've tried :
    treetable.getColumnModel().getColumn(0).setWidth(100);
    and it doesn't work at all !!
    please, ...
    delph :)

    Not a stupid topic. You have to have a phd in swing to understand column widths in JTable. there;s no guarantee that what I sugest will solve you problem though....
    Use TableColumn.setPreferredWidth(). You may have to create your own column model and implement the getPreferrredWith() method. Also make sure the Jtable.setAutoResizeMode(int mode) is set to what you need (I'm not sure if it makes any difference... but just in case)
    Good luck,
    Gilles

  • Trouble with DataGrid's last column width

    I have a datagrid with thirty columns.
    When I use the mouse to drag the window and resize its size,the last column width becomes more and more wide,and the previous column width is squeezed small.
    If anybody else came accross the same problem,can you share your solution?
    Thanks,
    April

    If horizontalScrollPolicy=”off” then there is an attempt to fit all columns within the width of the DG while respecting minWidth of the columns.  Make sure the minWidths allow the columns you want to shrink can shrink.
    However, there is still a chance of round-off error.  I think the only solution may be to set the width of each column as you want it on a resize event from the DG.

  • 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);

  • Horizontal scrolling in a JTable with fixed-size columns

    Hello,
    I have come to a roadblock concerning the following issue. Perhaps someone can share their ideas...
    I have a JTable with three fixed-size columns. I implemented a JScrollPane with vertical and horizontal scrolling. However, the text inserted into the last column is too long to fit in the specified column width. I would like to be able to scroll the table so that I can view all of the text in the last column. Right now, the text cuts off and ends with three dots (...). Is there a way in which a horizontal scroll bar can be implemented to view all the text in the last column?
    Here is a portion of my code:
    num_of_rows_Table2 = (int) Math.pow(3, num_of_vars);
    String[] colunmNames_Table2 = {"Decimal Identifier", "Ternary Identifier", "Cancellation of nonimplicants"};
    dataModel2 = new DefaultTableModel(colunmNames_Table2, num_of_rows_Table2);
    SpaceOfTermsTable = new JTable(dataModel2);
    for (int z = 0; z < num_of_rows_Table2; z++)
    SpaceOfTermsTable.setRowHeight(z, row_height);
    SpaceOfTermsTable.setBounds(new Rectangle(x1_Table2, y1_Table2, width_of_pane2, height_pane2));
    SpaceOfTermsTable.getTableHeader().setReorderingAllowed(false);
    for (int i = 0; i < 2; i++)
    TableColumn col = SpaceOfTermsTable.getColumnModel().getColumn(i);
    col.setMinWidth(colwidth_Table2);
    col.setMaxWidth(colwidth_Table2);
    col.setPreferredWidth(colwidth_Table2);
    TableColumn lastcol = SpaceOfTermsTable.getColumnModel().getColumn(2); lastcol.setMinWidth(lastcol_Table2);
    lastcol.setMaxWidth(lastcol_Table2);
    lastcol.setPreferredWidth(lastcol_Table2);
    SpaceOfTermsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    scrollPanel2 = new JScrollPane(SpaceOfTermsTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPanel2.setAutoscrolls(true);
    scrollPanel2.setBounds(new Rectangle(x1_Table2, y1_Table2, width_of_pane2, height_pane2));
    Thanks in advance for all of the help!

    Hi, I hava a similar problem than yours - can you tell me how you sorted out yer's?

  • Is there a way to make the last column in finder auto expand?

    I know that you can double click the double bar at the bottom right . . . but can't the finder be set to auto expand on the last column so i don't have to click that thing every time i wish to see the long named files ?
    Perhaps i should just use Bridge but it seems so slow and cumbersome compared to Finder.
    thanks for any advice.
    PS . . . is this available on the newest OS . . . going to upgrade one of these days.

    No, the finder's column view does not have auto resizing columns.
    It does have auto condensing of file names for the narrow display.
    Which is what you are trying to overcome.
    To accomplish your task, switch to list view.
    Select your file. Then switch back to column view.
    The trick is to learn your FINDER command key short cuts.
    command 1 = icon view
    command 2 = list view
    command 3 = column view.
    So you would press [command] and [3] to view the columns.
    Navigate about until you get a column of unhelpfully condensed names.
    Switch to list view by pressing [command] and [2]
    Select the file from the fully displayed names list.
    At this point you can press [command] [down arrow] OR [command] [o] to enter/open the selected item;
    or Switch back to column view by pressing [command] and [3] then continue browsing deeper.

  • 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

  • Unable to filter the report by clicking the last column's name

    Hi,
    I have interactive report page having lots of column. All columns were not fitting in the screen so I added a code in the region--- header and footer section---
    <div style="overflow: auto; width: 1220px; height: 700px;">
    I got a scroll bar at the bottom. But a new problem arised. When I am trying to filter the report by clicking the column name in the report page , a popup is opening for the first column but the pop up is not opening for the last column. For the middle columns, the popup is opening but not below its name. This pop is for filtering the report based on that columns.
    Please give some idea to fix this bug.
    Thanks,
    Chandra Bhanu

    You could try to display as many columns as fit your screen, and put the rest of your columns as form fields in a detail view, somewhat like this:
    http://apex.oracle.com/pls/apex/f?p=vincentdeelen:report_details_in_iframe_v1
    Please tell the steps how to do it.
    Thanks,
    Chandra Bhanu

  • How do I create a new row on tab out of the last column, last row?

    JDev 11.1.2.1.0.
    I've seen a few topics on this but none that I think were really very good solutions.
    Use Case:
    On tab out of the last column in the last row, a new row should be added to the end of the table. Bonus points for setting the focus to the first <af:inputText> of the newly created row.
    Complications:
    1. I'm having a heck of a time trying to find a function that returns the column's displayed index. Sadly, <column binding>.getDisplayIndex() returns -1 unless the user has manually re-ordered the column.
    2. Value Change Listeners only fire if there is a value change. Guess that means I need to do client/server listeners to check each and every <af:inputText> for a tab press?
    3. I'm not even going to get into setting the focus. With all the templates, regions, etc. going on, it's dang near impossible.
    Any ideas on how to attack this one?
    Will

    Hi,
    You will need to use the Run Engine Installation Wizard found on the Tools menu. In addition you need to create a installation set for the operator interface.
    Look at Chapter 16 Distrubuting TestStand ( chapter 17 for version 2).
    Once you have created your installation, install is on your new system.
    The serial number etc is part of the process model. When you run the entry point 'Test UUTs' the PreUUT callback is executed which asks the user for the serial number.
    Hope this helps
    Ray Farmer
    Regards
    Ray Farmer

Maybe you are looking for

  • Transport Basics

    Hi All, I have few questions on Transport Request in ABAP. 1) How to do we handle requests numbers when deleting an object from data dictionary and creating those with the same names? 2) could both delete and create entry be put into single request?

  • Characteristics for Item of a Order in BAPI

    Hi, My requirement is to create a return sales order using a BAPI from a inbound file for AFS Material. I am using BAPI BAPI_CUSTOMERRETURN_CREATE which has interface almost same as any other Sales Order creation BAPI. When a AFS material data is ent

  • Contacts Editor & Related Issues

    Hi everyone, I've got quite an annoying problem with Contacts Editor - when I edit any of my contacts from my phone the name and surname appear in a second line of the field on the phone. It means that in the contacts list I can see a "..." and nothi

  • Fetching molga from org unit

    hi all, to fetch country grouping fron org unit i have to first read infotype 1008 then read t500p.is there any table from which i can directly fetch molga from org unit. please help pratyush

  • UI to small

    I have indesign photoshop and User interface to small cc. I am using an iMac 27" screen. all my UI menus are so small i can barely see them. Is there a way to change there size.