JTable Model   --  How to set the width of columns

Hello,
This project of mine is due in 2 days. :(
I am using AbstractTableModel and I can't figure out how to set the columns' width inside my JTable?
This following code does not work.
int vColIndex = 1;
TableColumn col = table.getColumnModel().getColumn(vColIndex);
int width=399;
col.setPreferredWidth(width);Please remember, that I'm using AbstractTableModel and not just simple JTables.
Thanks in advance.

The DataModel (AbstractTableModel or otherwise) has nothing to do with the table column size. The DataModel is used to store data.
When you create a JTable using a DataModel then a TableColumn is created for each column in the DataModel using a default column size. The normal order of creation would be:
TableModel model = new DefaultTableModel(...);
JTable table = new JTable(model);
Now that the table and table columns are created you can change the size of the columns:
int vColIndex = 1;
TableColumn col = table.getColumnModel().getColumn(vColIndex);
int width=399;
col.setPreferredWidth(width);
So your code looks ok.
However, if somewhere in you code you do:
a) table.setModel(...)
b) fireTableStructureChanged();
then the table columns are recreated based on the current DataModel and the table column size would be reset to the default values.

Similar Messages

  • HELP Friends!!! How to set the width of columns of JTABLE?

    Hi!
    How to set the width of a particular column in JTable?
    I tried using headerRenderers and though I'm able to set the color and font of the header (using getTableCellRendererComponent method)I can't change the size.
    Pls some one help me..it's very urgent.
    Thanks in advance.
    Regards,
    Naval

    JTable.getColumnModel().getColumn(i).setWidth(width). There are also setPreferredWidth, setMaxWidth and setMinWidth methods.

  • How to set the width for a selectManyShuttle component

    Hi,
    I'm using selectManyShuttle component from Oracle ADF Core and some of the items in the showing list are long, therefore the width of selectManyShuttle expands the page. How to set the width property for selectManyShuttle component? After that does selectManyShuttle provide horizontal scrollbar as well?
    Thanks in advance,
    lapi
    Message was edited by:
    [email protected]
    Message was edited by:
    [email protected]

    Solution here:
    Re: ADF Faces Scrollable Panel or Scroll Bar inside a component
    Regards
    Grant

  • How to set the WIDTH and ALIGN of h:column in h:dataTable ??

    How to set the WIDTH and ALIGN of <h:column> in <h:dataTable>??
    Thanks a lot!

    Hi,thanks to your reply.
    Now I find a more convenient appraoch to set column's width and align respectively:
    <h:dataTable ...>
    <h:column>
    <f:facet name='header'>
    </f:facet>
    <h:outputText style="width:80px; text-align: right;" value='#{row.fieldA}'/>
    </h:column>
    <h:column>
    <f:facet name='header'>
    </f:facet>
    <h:outputText style="width:120px; text-align: left;" value='#{row.fieldB}'/>
    </h:column>
    </h:dataTable>
    It works fine.
    ^-^

  • How to set the data fields column wide at sqlplus

    Dear Sir/Madam
    I would like to know how to set the data fields column wide at sqlplus
    Thanks
    Francis

    see
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch6.htm#sthref1131
    and the FORMAT clause of the COLUMN command in
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12013.htm#BACHCABF

  • How to set the width of a cell in JTable?

    I have created a JTable and I want to set the width of cells.How can I do that?

    This is now the third person to tell you that Swing questions should be posted in the Swing forum.
    You have several postings out there where you have been given an answer but you haven't bothered to respond to the posting. Indicating whether the suggestion was helpfull or not. I guess you really don't want help from people in the future.

  • How to set the width of DataGridColumn dynamically?

    What I want to do is, load data from a text file and put into a DataGrid component, the fields of ech record in the text have fixed length, and are seperated by a space, like this:
    personal.txt
    50 Uvwxyz  Male    123456789
    60 Hijklmn  Male    67890123456789
    30 Abcdefg Male    123456789012345
    40 Opqrst   Female 987654321012345678
    the configuration file is column.xml:
    <dgcolumn>
         <personal>
              <len>20</len>
              <title>Name</title>
         </personal>
         <personal>
              <len>3</len>
              <title>Age</title>
         </personal>
         <personal>
              <len>6</len>
              <title>Sex</title>
         </personal>
         <personal>
              <len>20</len>
              <title>IdNumber</title>
         </personal>
    </dgcolumn>
    First I load the column.xml into an arrColumn, then read the personal.txt and seperate the record by the width( "len" in the xml file ), and put the seperated fields into another arrField, set the arrayFld as the dataProvider of a DataGrid, thus, the title can be showed as the headerText of the DataGrid and the data can be loaded correctly.
    private function handleComplete( event:Event ):void
         var arrField:Array = new Array();
         var arrFile:Array = loader.data.split(/\n/);
         for( var i:int = 0; i < arrColumn.length; i ++ )
              arrField[i] = convIcom( arrFile[i] );
         adgFile.dataProvider = arrField;
         trace( "The data has successfully loaded" );
    private function convIcom( strRecord:String ):Object
         var key:String = null;
         var dataField:String = null;
         var offset:int = 0;
         var obj:Object = new Object();
         if( strRecord.length > 0 )
              for( var i:int = 0; i < arrColumn.length; i ++ )
                   dataField = strRecord.substr( offset, arrColumn[i].len );
                   key = arrColumn[i].title;
                   obj[key] = dataField;
                   offset += arrColumn[i].len + 1;
         return obj;
    <mx:DataGrid x="10" y="100" width="400" id="dgFile" />
    The problem is, the width of the DataGridColumn is average, how to set the column width by the length of each field? I can calculate the rate of each field ( field / fields ), but I don't know how to change the property of the DataGridColumn.width.
    Thanks for helping.

    In the above post, I pasted an old version of personal.txt, so I paste it again:
    personal.txt
    Uvwxyz  50 Male   123456789
    Hijklmn 60 Male   67890123456789
    Opqrst  40 Female 987654321012345678
    Abcdefg 30 Male   123456789012345
    And I have another question, when the data is loaded into the DataGrid, the fields of each record are ordered in alphabetical order ( the "Age" column will appear firstly, then "IdNumber", "Name", "Sex" ), not as the order in column.xml, how to make it keep the sequence of the xml file?
    Thanks again.

  • How to set the width of a shuttle?

    Hi
    I have a group which is shown in intersection-shuttle style but the problem is that it breaks some rows into two lines and i want to make the shuttle a bit wider. How could I set the width of the shuttle. Apparently the Group Width attribute of the group doesn't work for this.

    You could try this using the inlineStyle property of the shuttle component in the generated page. Not sure that works though. You better ask this on the JDeveloper forum.
    If it works you can create a custom template to include the inlineStyle property during generation.
    Steven Davelaar,
    Jheadstart Team.

  • How to set the width of a Column

    Hi friends
    I have problem with setting up the Width for each column. Let us i want to set different column width for each Column.
    That is for first column the Width may be Different and the other column the width may be different.
    So please help me out on this Issue
    Cheers
    Jofin

    How to set the width of a ColumnWhat component are you talking about? Are you talking about the width of a column in a JTextPane?
    Have you read the API for the component in question?
    Have you followed the link titled "How to Use...." to the Swing tutorial?
    Learn to read the API and ask a proper question with all the relevant information.

  • Please help me :How to set the width and height for my View page "test.htm"

    Hi,
        I have controller class. When i call the view[test.htm]from this controller class ,i am getting the view with output tableview..it is fine.
    My requirement:
                 the output view window is showing full browser window. I want the view output like showModeldialog. I want to set the width and height for the output view window. How is possible?
                 or
    i want to call the test.view in the window.showModelDialog..
    Please help me .. Urgent requirement.

    Yes you can set the width & Height of the view as follows..
    <div style="width:580px; height:750px; margin-top:15px; overflow:auto;">
    <htmb:form......>
    </htmlb:form>
    </div>
    <i>*Reward each useful answer</i>
    Raja T

  • How to set the width: IF_WD_SELECT_OPTIONS- add_parameter_field

    Hi everyone,
    I would like to know if there's a way to set the width of UI controls defined for IF_WD_SELECT_OPTIONS.
    In particular I've created a selection screen using
      wd_this->m_handler_simple_left->add_parameter_field( i_id = 'CONTRACT_DESCRIPTION'  i_value = lr_field
                                                        i_description = 'Contract description'
                                                        i_within_block = 'BL01'  ).
    but I'm unable to set the width of this field and the final rendering isn't very nice at all (all input fields have different data types and different size).
    Thank you.
    Regards

    Hi,
    I think we dont have any width type parameter to set width in selectoptions. The width comes directly from Domain.
    Cheers,
    Kris.

  • How to set the width and heigh in the popup window

    Hi All,
    I tried to show a report in a popup window style.
    In the column link section, I defined the URL like the following:
    javascript:popupURL('f?p=&APP_ID.:128:&SESSION.::&DEBUG.::P128_PAY_RATE,P128_PAY_TERMS:#PAY_RATE#,#PAY_TERMS#'). how and where to set the height and width for page 128?
    Thank you,
    spark

    Here is a sample of the JavaScript function I re-use that opens a popup window. You'll notice that it includes the width and height of the popup window:
      function callTCPopup (formItem1) {
        var formVal1 = formItem1;
         var url;
      url = 'f?p=&APP_ID.:1111:&APP_SESSION.::::P1111_TC_ID:' + formVal1;
      w = open(url,"winLov","Scrollbars=1,resizable=1,width=800,height=600");
      if (w.opener == null)
      w.opener = self;
      w.focus();
      }You could also look at using a Modal Page (Skillbuilders' plugin - watch the video for use).

  • How to set the width and height of the displayed image in a button

    How can I please specify the size of the image that I display in a button which I create dynamically.
                HtmlCommandButton button = new HtmlCommandButton();
                button.setImage(image.getUrl());Thanks in advance
    Message was edited by:
    WebService

    Follow some CSS tutorials to learn more about it.
    Here is a page with some links: http://www.google.com/search?q=css+tutorial
    Then you're doing or interpreting something wrong. The methods are actually there. I can play with them in my playground and they are also described in the the HtmlCommandButton API: http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/component/html/HtmlCommandButton.html

  • How to set the width of input text

    hi ,
    i have form, which have few input text.the layout of form is not correct.some input text length is so long, it difficult to make in all input text in same length.Some inputtext have varchar2(1000).how to do that?

    hi,
    first of all mention the jdev version u r working on
    In the input text property there is property called columns.You can give some value like 200 or 300 according to your need.
    try this.

  • How to change the width of column guide itself?

    i'm doing a trifold brochure and set it up that way in layout.  the space between the column guides (represented by the thin purple lines) is too narrow.  i want to make it wider.  i thought that that space was the "gutter" but when i change the gutter from the default to .25" nothing changes in the page.  i would expect the thin purple lines to more further apart.  am i adjusting the wrong thing or what? thank you!

    The guides themselves don't really do anything. They are simply visual cues that you as the designer can use or ignore. To get the actual column gutters to change you need to go into "text frame options". Use Command-B (Mac) or Control-B (PC) or right click to access contextual menus and choose text frame options from a list. Once the dialog pops up, you can change the gutters. If you want the actual gutters and the guides to match, you'll also have to edit the guides. You can do that under the layout menu, "margins and guides."
    Hope that helps

Maybe you are looking for