Can't set custom column widths in JTable

I'm trying to set custom columns widths. They are set as I wish but then they are reset to default values (all columns have the same size). This is caused by method JFrame.setVisible(true) which invokes JTree.setWidthsFromPreferredWidths(). It can be investigated from following stack trace printed when a column being resized (see below).
How to prevent this auto width sizing?
P.S. can't override JTable.setWidthsFromPreferredWidths(); seems it's private
table = new JTable(model) {
     public void columnMarginChanged(ChangeEvent event) {
          new Exception("stack trace").printStackTrace();
          super.columnMarginChanged(event);
// setting here custom columns widths via table column model ...java.lang.Exception: stack trace
     at mtu.gui.TrackList$1.columnMarginChanged(TrackList.java:30)
     at javax.swing.table.DefaultTableColumnModel.fireColumnMarginChanged(DefaultTableColumnModel.java:615)
     at javax.swing.table.DefaultTableColumnModel.propertyChange(DefaultTableColumnModel.java:679)
     at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
     at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
     at javax.swing.table.TableColumn.firePropertyChange(TableColumn.java:249)
     at javax.swing.table.TableColumn.firePropertyChange(TableColumn.java:255)
     at javax.swing.table.TableColumn.setWidth(TableColumn.java:482)
     at javax.swing.JTable$2.setSizeAt(JTable.java:2242)
     at javax.swing.JTable$5.setSizeAt(JTable.java:2336)
     at javax.swing.JTable.adjustSizes(JTable.java:2372)
     at javax.swing.JTable.adjustSizes(JTable.java:2340)
     at javax.swing.JTable.setWidthsFromPreferredWidths(JTable.java:2250) <======
     at javax.swing.JTable.doLayout(JTable.java:2165)
     at java.awt.Container.validateTree(Container.java:1089)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validateTree(Container.java:1096)
     at java.awt.Container.validate(Container.java:1064)
     at java.awt.Window.show(Window.java:455)
     at java.awt.Component.show(Component.java:1134)
     at java.awt.Component.setVisible(Component.java:1089) <=====
     at mtu.gui.Test.test_03(Test.java:56)
     at mtu.gui.Test.main(Test.java:29)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:324)
     at com.intellij.rt.execution.application.AppMain.main(Unknown Source)

When I create the table I have code like this:TableColumn col = getColumnModel().getColumn(2);
col.setMinWidth(width + 4);
col.setMaxWidth((int)(width * 1.2));Works just fine for me. The setWidthsFromPreferredWidths() method will use these limits as far as I can see.
PC&#178;

Similar Messages

  • How can i set the column width in the jtable?

    how can i set the column width in the jtable?
    can anybody send me a simple example??

    TableColumn column = table.getColumnModel().getColumn( columnIndex );
    column.setWidth( desiredColumnWidth);
    column.setMinWidth( desiredMinColumnWidth);
    column.setMaxWidth( desiredMaxColumnWidth);

  • How to set the column width of JTable

    I want do remember the column width and write it to a file, when the window is started , the column width is read from the file and the table is set as that. I also want the column width is not fixed and can be changed by mouse.But I am always failded.
    How to do? would you please help me!
    Thanks a lots.

    To "remember" the column widths, add a mouse listener to the table header. Upon mouseReleased(), get the column widths and save them to your file. When the application starts next time, get the stored widths and set them using:
    table.getColumn("XXX").setPreferredWidth(...);
    By default, your columns are adjustable, but you can use:
    table.getTableHeader().setResizingAllowed(true);

  • OLE2 how to set a column width of an excel file i'm creating?

    how can i set the column width in an excel file i'm creating with ole?
    or even, haw can i set the auto-fix properties?

    Hallo !
    SORRY MY ENGLISH is very BAD.
    I tried to set page header and  footer in Excel sheet with abap ole
    DATA : BEGIN OF enter,
             x(1) TYPE x VALUE '0D',
            END OF enter.
    DATA : format(255) TYPE c.
    FORM set_page_sheet.
      CALL METHOD OF excel 'ActiveSheet' = sheet.
      CALL METHOD OF sheet 'PageSetup' = pagesetup.
      SET PROPERTY OF pagesetup 'Orientation' = xllandscape.
      SET PROPERTY OF pagesetup 'PrintTitleRows' = '$9:$12'.
      CLEAR format.
    ERROR
      CONCATENATE 'PAGESHEET' enter-x 'PAGE &P/&N' INTO format.
    ERROR
      SET PROPERTY OF pagesetup 'RightHeader' = format.
      CLEAR format.
      CONCATENATE ' Text 1 ' enter-x 'Text 2'
    enter-x 'Text 3 ' INTO format.
      SET PROPERTY OF pagesetup 'RightFooter' = format.
      FREE OBJECT pagesetup.
    ENDFORM.                    " set_page_sheet
    Activate report -
    ERROR - The enter-x must by data type c or another then data type x
    Thanks for answer.

  • How can I set column width in JTable?

    How can I set column width in JTable?

    Also, read the JTable API before posting questions. You will find a link to the Swing tutorial on "How to Use Tables", which contains an example of doing exactly this.

  • 10.8.6 Column view. Can we set the window width to resize to it's longest file?

    I have a MacBook Pro, 10.8.6. I always have my windows open in Column view. Can we set the window width to resize to it's longest file? I'm always having to manually make the width wider and it's annoying.
    Thanks

    Hi, the latest OSX is 10.7, soon to be 10.8, there is a way in Leopard/10.5 & Snow Leopard/10.6 to make finder display that...
    http://osxdaily.com/2007/12/02/show-full-directory-path-in-finder-window-title-b ars/
    A possible workaround for Tiger/10.4 is both of these which show the full path & is Copyable...
    Find Any File...
    http://apps.tempel.org/FindAnyFile/
    EasyFind...
    EasyFindPath
    Near the bottom of the page.

  • Set column width in JTable

    I have two columns in a JTable and I am trying to set the column width for the first.
    I am trying to this by
    getDataTbl().getColumnModel().getColumn(0).setHeaderValue("Index");
    getDataTbl().getColumnModel().getColumn(1).setHeaderValue(" Data ");
    int width = ((String)getDataTbl().getColumnModel().getColumn(0).getHeaderValue()).length();
    getDataTbl().getColumnModel().getColumn(0).setPreferredWidth(width);
    but it doesn't reset the width. I want the first column width to be smaller than the second which should be much larger width.
    Any suggessions to this?
    Thanks.

    Hi there
    Use this JTable method
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);This should solve your resize problem
    ICE

  • How to set displayed column width for a search help

    I have created an elementary search help for a custom field with a value table behind it.
    The search help functions correctly, but when displayed the column widths are all 10 characters. The user has to adjust the column to view the descriptive text.
    Can anyone tell me how to set default column widths for the help?

    Please  open you Elementary search  help  and see the Column  width   behind the Fields of your ...there  increase the width of the fields
    "Activate it  and refresh
    reward  points if it is usefull .....
    Girish

  • Need custom column widths in Append Text Table to Report

    I need to print reports with tables of different column widths specified for each column, as the contained fields vary in width from just 3 characters in one column to 40 characters in another.  Also we are trying to match the reports generated by a non-labview routine.  In the past I have been able to achieve this by editing the Append Table to Report vi, working my way through the inner hierarchy to replace the DBL numeric COLUMN WIDTH control with a DBL numeric array.  The innermost vi, Set Table Column Width, assigns the numeric to a property node in a for loop, so the change is simple: replace the scalor with an array and enable indexing on the for loop.  Of course, after each Labview upgrade, I've had to go back in and repeat these edits on the overwritten upgraded vi's.  This time there is a problem.  The new version of this toolkit is object oriented, and disturbing these vi's wrecks the class methods in a way I don't understand (mostly because I've had no dealings with object oriented programming) and which cannot be undone.  I recently tried this and after not being able to fix the problem even with phone support, I had to spend the next two days unistalling and reinstalling Labview!  I desperately need a way to achieve this functionality without killing the toolkit, which is used (in its original functionality) by another absolutely critical program.  PLEASE HELP!
    The hierarchy is as follows:
    NI report.lvclass:Append Table to Report (wrap)
    NI report.lvclass:Append Table to Report 
    NI Standard report.lvclass:Append Text Table to Report
    NI Standard report.lvclass:tables
    NI Report Generation Core.lvlibet Table Column Width

    There is a highly relevant thread under discussion here:
    http://forums.ni.com/ni/board/message?board.id=fea​tures&thread.id=429
    You may wish to read it and chime in as it is a discussion of LabVIEW's policy (and possible change in policy for the future) concerning the handling of non-palette VIs between LV versions.
    Rob Hingle wrote:
    > Is that to say NI will not be helping me with this?  Pretty disappointing lack of support, seems
    > like a terrible idea to go to object oriented if even your own application engineers can't figure
    > out such a simple fix.  Gotta give NI a huge thumbs down on this one, thanks for nothing.
    I doubt that it is a simple fix -- our AEs are generally top notch at figuring out solutions for customers -- if it were simple, my bet is they'd have solved it. Asking an AE to work around a bug is different from asking them to rearchitect the toolkit. You are asking them to add a feature that the new version of the toolkit is not
    designed to support. The difficulty in doing this is completely independent of the decision to use LabVIEW classes to implement the toolkit. If any piece of software is not designed with a particular use case in mind, what may be a simple tweak under one design may become a very hard problem under another design.
    In your case, the solution is very straightforward: Use the older version of the toolkit. Any time you create a custom modification of the VIs that ship with LV or one of its toolkits, you should make your own copy and have your VIs link against the copy. LabVIEW promises to maintain all the public functionality version over version. Usually we succeed at that. What we do not promise is to maintain our private implementation of that functionality. It is impossible for LabVIEW (or any other software library) to maintain all of its private internal operations while still continuing any development. Using a copy of the original VIs shields you from having to recode your changes every version (something you've already mentioned is a chore) and it guarantees that functionality that you relie upon does not disappear.
    I hope you are willing to be understanding of this situation and not hold it against the AEs working on this. They try hard to provide excellent customer service, and spend lots of time inventing custom solutions for our users.  This happens to be a situation where the correct fix is not to modify the new toolkit version to do something it wasn't designed to do but to modify your development process so that the problem is solved now and into the future. 

  • Is there any way to set default column widths in the Finder's Column view

    When my Finder windows open in column view, all the columns are always VERY wide. I have to then spend time resizing them to a managable width. Is there any way to set default column widths in the Finder's Column view?
    <Re-Titled By Host>

    No, because you can't set a columns view default.
    27" i7 iMac (Mid 2011) refurb, OS X Yo (10.10), Mavs, ML & SL, G4 450 MP w/10.5 & 9.2.2

  • Column width in JTables.Help needed!!!!

    Hi
    I am trying to print out a JTable and have had a few problems along the way but have managed to solve them all so far apart from this one. When the JTable is shown on screen it doesn't make the columns wide enough . I ahev managed to find some code from these forums but it doesnt resize correctly if the Column headings contain more text than any of the data (If you know what i mean). Below is the code i am using
    public void sizeAllColumnsToFitData (JTable table)  {
        for (int col = 0; col < table.getColumnCount (); col++)  {
          TableColumn curColumn = table.getColumn (table.getColumnName (col));
          if (curColumn == null)
            continue; // not a valid column skip
    //  Translate to the model
          int modelColumn = curColumn.getModelIndex ();
    //  Loop for all rows in this column looking for the widest piece of data
          int maxColumnWidth = 0;
          for (int row = 0; row < table.getRowCount(); row++)  {
            TableCellRenderer curCellRenderer = table.getCellRenderer (row, modelColumn);
            Object value = table.getValueAt (row, modelColumn);
            Component curRenderComponent = curCellRenderer.getTableCellRendererComponent(table, value, true, true, row, modelColumn);
            Dimension cellDimension = curRenderComponent.getPreferredSize ();
            if (cellDimension.width > maxColumnWidth)
              maxColumnWidth = cellDimension.width;
    //  Set the column width to fit the maximum
          Dimension cellSpacing = table.getIntercellSpacing ();
          curColumn.setPreferredWidth (maxColumnWidth + (cellSpacing != null ? cellSpacing.width : 1));
      }I pass my table into here and it works fine apart from in doesnt take into consideration the size of the headings. Please Help ME!!!!

    java.lang.NullPointerException
         at database_testing.SLAMS.sizeAllColumnsToFitData(SLAMS.java:473)
         at database_testing.SLAMS.getInfo(SLAMS.java:364)
         at database_testing.SLAMS.getInfo_actionPerformed(SLAMS.java:434)
         at database_testing.SLAMS_getInfo_actionAdapter.actionPerformed(SLAMS.java:527)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
         at java.awt.Component.processMouseEvent(Component.java:5134)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)Also i think it may have something to do with my headerRenderer being null cus if i replace the line TableCellRenderer headerRenderer = curColumn.getHeaderRenderer(); with TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); then it doesnt come up with an error but only increase the size of the coluns (where neccessary by 2 characters)

  • New to portal: Setting the column width in portal QBE report

    I'm trying to set different widths to different columns in the QBE report. One of the columns in the report contains long descriptive text. With the default column width the reports runs into many pages and user has to scroll a lot. I would like to set the column width for this column so that it does not wrap for every 2/3 words. In the customization tab, I'm setting the width type to "Char" and selecting the number of characters to be displayed in that coulmn. Percent/pixel width type also didn't help. Should I set the Header width also?. I'm not sure where to set this header column width.QBE report just ignores these customization parameters and displays the report in default format. Please let me know if you have any idea/solution to this problem.
    Thanks
    Surya

    Hi,
    This is a bug and has been fixed 30984.
    Thanks,
    Sharmila

  • Why can't you adjust column width in pages for ipad?

    Why can't you adjust column width in pages for ipad?

    It's just one of the many, many features that have been removed. It all appears to be deliberate, not an oversight. Leave feedback for the Pages team using the link in the Pages menu.

  • How to set initial column widths for a table

    What I'd like to do is to control the initial column widths for a table.
    I'm building the table by using a class which extends AbstractTableModel. This class takes care of setting the headers and reading the data for the table.
    If I do the following:
    VarTableModel vtm = new VarTableModel(vi);
    JTable jt = new JTable(vtm);
    JScrollPane jsp = new JScrollPane(jt);
    frame.getContentPane().add(jsp);
    frame.setVisible(true);
    I will see a table in my window. The widths of the columns are equal and are a function of the horizontal dimension of the window.
    I have tried to set the width of a column by doing the following:
    TableColumn aColumn;
    aColumn = jt.getColumn(vtm.getColumnName(0));
    aColumn.setWidth(40);
    But this has no effect on what gets displayed. I can force the widths that I want by using 'setMaxWidth' but this has the unfortunate side effect of not allowing the user to make the column wider if they want.
    What I'd like is a way to specify the widths of the columns when initially displayed and then let the user adjust to their liking.
    I'm sure that there is a way to do this, but I don't seem to understand where to intervene in the process to produce the effect that I want.
    Any help or suggestions will be greatly appreciated!

    Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    add this line and try ur codeThanks for the suggestion! Unfortunately, it doesn't seem to do the trick. Here is an abbreviated segment of my code:
    vtm = new VarTableModel(vi);
    JTable jt = new JTable(vtm);
    // we want a horizontal scrollbar, so turn resizing off
    // and we want to control column widths
    jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    aColumn = jt.getColumn(vtm.getColumnName(0));
    aColumn.setWidth(40);
    . // same kind of thing for each column
    aColumn = jt.getColumn(vtm.getColumnName(4));
    aColumn.setWidth(400);
    JScrollPane jsp = new JScrollPane(jt);
    frame.getContentPane().add(jsp);
    frame.setVisible(true);
    If I do the above, the table gets displayed with each of the five columns the exact same width. So, the sizing of the columns is happening somewhere else despite turning auto resizing off.
    Where is that occurring and how can I intervene so that I can control the widths of the columns on initial display and still allow the user to adjust the widths if they so choose?

  • How to set the column width in the PDF exports of interactive reports ?

    Hello,
    I have a huge problem with the PDF export for the Interactive reports. I'm using APEX 3.2.
    I have to produce a PDF report in landscape format that show 21 columns. My problem is that the columns have a ridiculous short width and that the text inside the columns do not wrap in the columns. So I get things like that :
    Date Name
    2011 Leina
    I should see 2011-08-01 and the name Leinad Jan
    I tried several things to format the columns, but none of the them has any effect on the PDF itself.
    1) I used HTML code in the report query. It works well with the interactive report, but display the HTML tags in the PDF.
    2) I used css to set the width of my columns. It works in the interactive report, but not in the PDF, the column width do not change.
    It's like the report do not notice that my page format is Legal 14 x 8.5 (Landscape) and still believe it's 8.5 x 11 (which is "portrait")
    Do you have any idea so set the columkn widths in the reports ?
    Thank you !
    Edited by: leinadjan on Aug 1, 2011 11:15 AM

    To "remember" the column widths, add a mouse listener to the table header. Upon mouseReleased(), get the column widths and save them to your file. When the application starts next time, get the stored widths and set them using:
    table.getColumn("XXX").setPreferredWidth(...);
    By default, your columns are adjustable, but you can use:
    table.getTableHeader().setResizingAllowed(true);

Maybe you are looking for

  • Report background engine

    hi i am using reports6i. every time i run a report, the report background engine appears in my task bar. By closing the report, it still persists in the task bar, and i have to close it manually. Is there any way that by closing the report, the repor

  • How can I create a dynamic Dropdownlist

    Hi Experts, I am new in the adobe forms and I have this problem. I am working on a Dropdownlist in Adobe Interactive Form. In my case, my form will be used in Offline-ABAP system without any web dynpro application. I have an internal table containing

  • My iphone 4S is not connecting to the wifi!!

    all the my other devices are connecting but not my iphone!!it tells me that no networks found!! I've tried restoring the network setting and reseting the phone but nth have worked!

  • Text in MK02 effects which database table?

    Hi, I have added a Text (MK02->Purchasing->Extras->Text) in MK02. I am not able to find out, which table it affects. Please help me. Vijayanand.

  • Off topic?  Copyright info please

    I am a web designer and design pages mostly for small businesses. I am wondering about the ins and outs of copyrighting a web site. Does anyone on this forum, who is a designer regularly, copyright the sites they create? If so, are you copyrighting f