[Feature request] Runtime width of JTable columns based on attribute settings

I'm wondering if it's possible to let 'JClient' dynamically resize the columns in a JTable. Eg: I have set the width of some attribute of some ViewObject to 3. But when I run the application all columns are equally sized. I tried changing the JTable's property autoResizeMode (figuring it might override settings by JClient), but that doesn't seem to have any effect.
Also, 'grabbing' a column from the table through some manual coding and setting the width of that column doesn't seem to work either.
I've posted something regarding JTable Re: for specifically RIZWAN from PAkistan or anyone, but I'm curious to know if this 'Specialised editor for Grid Control (JTable)' that Grant Ronald spoke of, will include some sort of applicable functionality.
It's clear that we need some better (that is, 'any' ;)) way of manipulating columns in a JClient table.
Any comments?
Thanks.
Arno

We are currently looking into that.
The column width should not be controlled from the model, it is a setting on JTable, We are considering providing a JClient control (JUTable ??), which is a JTable in a scrollpane and give you more power over column width, column headers etc....
We are currently evaluating that.
It would mean that you've got a table control with properties allowing you to set these things on the control itself.
Currently you have to set the hints on the TableColumn.
Here is an example :
tableDeptView1.setModel(JUTableBinding.createAttributeListBinding(panelBinding, tableDeptView1, "DeptView1", null, "DeptView1Iter", new String[] {"Deptno", "Dname", "Loc"}));
tableDeptView1.getColumn("Deptno").setMaxWidth(75);
tableDeptView1.getColumn("Loc").setPreferredWidth(200);
tableDeptView1.getColumn("Loc").setMinWidth(100);
tableDeptView1.getColumn("Loc").setMaxWidth(450);

Similar Messages

  • Error giving a default value to a date column in the attribute settings.

    When im giving a default value to a date column in the attribute settings i get this error when im running my jsp page (bc4j web application):
    Error Message: JBO-25009: Cannot create an object of type:oracle.jbo.domain.Date with value: 31-dic-2099
    How can i fix that?
    Thank u

    The default date format for oracle.sql.DATE which oracle.jbo.domain.Date extends is "YYYY-MM-DD"

  • Feature request - iSync with Gmail, other web-based emails

    It would also be great if you could iSync the Mac's Address book with Gmail and other web-based email services.
    I know I can export contacts and load them in to Gmail. But you have to remember to do this each time you change an email address in the Mac's address book.

    I just got this email back from Plaxo. Apparantly Plaxo does not sync Address Book with GMail, yet. But they are planning to offer this feature in the future. Although he does not say whether this will be an automatic background synchronization.
    Hi Brian,
    Thank you for contacting Plaxo
    You can go ahead and download the Plaxo toolbar for Mac using this link "http:www.plaxo.com/downloads" and install the Plaxo toolbar for your Mac and download your contacts from your Plaxo online to your Mac address book. However, as of now you will not be able to sync your Plaxo online account with Gmail account. Very soon we will have this as a Plaxo feature.
    Please let me know if you have any further questions and concerns.
    Mark
    macbook black - ibook g4 - mini   Mac OS X (10.4.9)  

  • Update my Feature Request

    I posted a feature request. There is a column "update", but I couldn't find how to update (=edit and add some comment) my request. Do I have to post a new feature request and refer to the old one?
    Edited by: @chris on 30.03.2009 16:58

    1) http://www.apple.com/feedback/iphone.html
    2) Probably, since it's been brought up over and over in these forums since the iPhone was first released. The others users has similarly been pointed to the Feedback page.
    Regards.

  • Set JTable column width

    Hi,
    I would like to set the column width of JTable.
    ========================================
    JTable table;
    DefaultTableModel tableModel;
    tableModel = new DefaultTableModel();
    table = new JTable( tableModel);
    JScrollPane scrollPane = new JScrollPane(table);
    for(int i = 0; i < heading.length; i++)
    tableModel.addColumn( heading[ i ]);
    ========================================

    Did you run the tutorial code? Did it work?
    Now compare the tutorial code with your code to determine what is different.
    We can't tell you what is different based on the one line of code you posted:
    colModel.getColumn(i).setPreferredWidth(100);

  • Feature Request | Allow custom metadata per table/column to be stored

    Someone please correct me if there's already a feature that allows this...
    I'd like to see a feature where you can define a set of metadata that can be stored per table / column, and perhaps a trigger that updates that metadata.
    As a use case, it is sometimes necessary to find out how many records exist in a table, and the typical way of doing this is by running a statement like select count(*) from example_table;. With a large table, this statement might take a long time though, and certainly has overhead associated with it. If this is something that's done on a regular basis, like maybe even once every minute, wouldn't it be much better to store this number as metadata for the table that can be updated on inserts and deletes and then can be queried? It might involve extra overhead on an insert or delete statement to add to or subtract from this number, but then for some applications the benefit of getting the count quickly might outweigh the extra overhead.
    Another use case is finding a minimum or maximum out of a table. Say you store a date and you need to find the max value for some feature in your application; with a large table, and especially if its a date with accuracy to the millisecond where an index wouldn't help much because most values are unique, it can take quite a bit of time and overhead to find that max value. If you could define for that column that you'd like to store the max value in metadata, and could query it, it would be very quick to get the info. The added overhead in this scenario would be on insert, update or especially on delete, the value would have to be updated. But in some applications, if you don't expect alot of deletes or updates on this column, it might be worth the added overhead to be able to quickly find the max value for this column.
    I know you could probably make a separate table to store such info, and write triggers to keep it up to date, but why not have a built in feature in Oracle that manages it all for you? When you create a table, you could define with the column definition something like 'METADATA MAX' and it will store the max value of that column in metadata for you, etc.
    I know that the overhead of this feature wouldn't be good for most circumstances, but there certainly are those cases where it would be hugely beneficial and the overhead wouldn't matter so much.
    Any thoughts?
    Can this be submitted as a feature request? Am I asking in the right place?
    (p.s. while you're at it, make a feature to mimic IDENTITY columns from SQL Server!)

    I don't think what you mentioned is exactly what I was talking about. There's no min_value or max_value in the dba_tab_columns table; there's only high_value and low_value, and they are stored in binary. And I believe to be accurate in the use cases that I suggested, you would have to analyze the table after every insert/update/delete. So no, that's not the same feature I've asked for, although I appreciate the feedback.
    Also, the num_rows in dba_tables relies on the table being analyzed too, so for a table that stores temporary date to be processed where you want to know the size of the queue every few seconds, it wouldn't make sense to analyze the whole table every few seconds when all you want is a count of the records, and it's also inefficient to use the COUNT function with every query when it would be much faster to store the count in some metadata form that is updated with every insert or delete (adding to a count and subtracting from a count with each insert/delete is WAY faster than analyzing the table and letting it literally recount the entire table every time).
    So again, while I appreciate the feedback, I don't think what you mentioned addresses either of the use cases I gave. I'm talking about a different kind of user defined metadata that could be stored per table/column with rules to govern how it is updated. Not you standard metadata that requires an analyze and isn't real time. I also only gave a few use cases, but the feature I'm really looking for is the ability for users to define many different types of custom metadata even maybe based on their own logic.
    Again, this feature could be implemented right now by creating a USERMETADATA table for every standard table you have, and then using triggers to populate the info you want at the table level and column level, but why do that when it could be built in?
    Also, I don't really agree that having to create a trigger/sequence for every table instead of setting a column as IDENTITY is better. It's cumbersome. Why not build these commonly used features in? It can create a trigger/sequence behind the scenes for all I care, but why not at least let someone mark a column as IDENTITY (or use whatever other term you want) at the time of table creation and let it do everything for them. But that's off-topic; I meant it for more of a side comment, but should really have a separate post about it.

  • Tweaking JTable column widths

    One of the things I don't seem to be able to do cleanly is programatically sizing column widths. What I'm trying to do, presently, is to try and set column widths on numeric columns according to class.
    This is what I'm trying:
       public static void tweakColumns(JTable table) {
            TableColumnModel tcm = table.getColumnModel();
            TableModel data = table.getModel();
            table.createDefaultColumnsFromModel();
            for(int i = 0; i < tcm.getColumnCount(); i++) {
                TableColumn col = tcm.getColumn(i);
                Class cls = data.getColumnClass(i);
                if(cls.equals(Percentage.class))
                    col.setPreferredWidth(44);
                else if(cls.equals(Money.class))
                    col.setPreferredWidth(60);
                else if(cls.equals(Integer.class))
                    col.setPreferredWidth(20);
            table.revalidate();
        }I've tried calling this when I set the table up, I've tried defering it with invokeLater. The problem appears to be when there's plenty of space the additional space is applied indiscrimitely, smothering my settings, whereas I want the extra to be applied to the columns I don't set preferences for (typically text fields).
    I don't want to impose a maximum column width if the user choses to resize columns. I want to control the distribution of space when it's done by swing.

    I think your only solution is to set the Preferred sizes of all the columns, even the textfields.
    I have done similar thing and it works but only when all the preferred sizes of all the columns are set.
    If you record the total width available to all columns before you start setting the preferred sizes of the Percentage, Money and Integer columns you can subtract the sizes of these columns as you set them. When you come out of the loop you will have a value that is what is left of the width. You can then set all the remaining unset columns to values based on this remaining width.
    i.e. you have 700 pixels total width the the initial loop you have fields that result in 340 pixels being allocated. You have 360 pixels left over. If you have 3 remaining unset fields then you then set their preferred sizes to be 120 pixels. This, I think, will force swing to allocate in the way you want.
    I've never tried it but you might find setting the textfields to unrealistically large Preferred sizes will make swing attempt to do its best and end up with what you want.

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

  • Resize jtable column width

    I am trying implement a utility in JTable by which when a person clicks on the column header, the whole column should resize according to the cell which has lengthiest data. If you have seen this in MS Excel where by clicking on the column this happens. I want the same thing.
    Is there anyway already defined in javax.swing?
    I have added a Mouselistener on Tableheader and when the person clicks on a column header, I first finds out the column index. Now on that column index scan the whole column for the lengthiest data. After finding the lengthiest data I set the preferred width for that column and call doLayout on the table object. In this case the problem is of font as the font is not fixed width. The multiplication factor which returns the pixel doesn't gives the right pixel width. Is there any way by which I can find pixel width of a String?

    Use the following code to compute the width of a
    column in pixels required to display the maximum sized
    string in the table column:
    FontMetrics fm =
    table.getFontMetrics(table.getFont());
    int width =
    SwingUtilities.computeStringWidth(fm,maxSizeString)
    //then to set the width of your column:
    TableColumnModel columnModel =
    table.getColumnModel();
    TableColumn column =
    columnModel.getColumn(YOUR_COLUMN);
    column.setPreferredWidth(width);Rizwanthx that was usefull

  • Feature Request "Copy of column-name" in 2.1.1 not working

    Scanning all the feature requests added to 2.1.1, i came across to the following one:
    Title: Copy of column-name
    Description:
    after getting the query result it would be greate if we can mark the column-name and the copy the name of the column to the clipboard for further use (e.g. select colum_name from table ...)
    Comment:
    Try 2.1.1. You can drag a selection of columns to the worksheet. If not, then please provide more detail in future request.
    Status: In Release 2.1.1 ;
    Now i've tried few times to drag the column from the query result into the worksheet but it doesn't work. The only thing which works is to change the columns orders in the grid result.
    Anybody experience the same result?
    Dani

    @Raghu
    I'm already aware of this and it's working but the downside is that it copies the cell value too which i don't see the point.
    If i want the cell values than i can export or copy them.
    The request description was different though.
    @K
    Unfortunately you can't drag the column name from the navigator or result grid. Would be nice if it would.
    Is anything else i can do to get this fix or are you gonna raise a CQ for this?
    Regards,
    Dani

  • What method should be used for resizing the particular JTable Column width

    I have a four table. Only one table which are on top have a table header. I want that when user resize the topmost table with a mouse other table colume also be resized automatically. So I want to know that what method should be used for resizing the particular JTable Column width.
    Thanks
    Lalit

    maybe you can implement a interface ComponentListener as well as ComponentAdapter with your topmost Table.
    for example:
    toptable.addComponentListener(
    new ComponentAdapter(){
    public void componentResized(ComponentEvent e){
    table1.setSize(....);
    table2.setSize(....);
    /*Optionally, you must also call function revalidate
    anywhere;*/
    );

  • JTable column width

    I am having trouble initializing column widths in my JTable.... after I create the table I use JColumn.setWidth(int) to set the width of every column. It doesn't work! the table sets
    default equal widths. Am trying like this :
         if(e.getSource()==column)
         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);     
    for(int i=0;i<table.getColumnCount();i++)
    table.getColumnModel().getColumn(i).setPreferredWidth(Integer.parseInt(column.getText()));
    modelTable.fireTableStructureChanged();     
         }

    Instead of setPreferredWidth(..), try setMaxWidth(..)
    table.getColumnModel().getColumn(i).setMaxWidth(Integer.parseInt(column.getText()));
    I does the trick for me.

  • JTable column auto-maximum width

    Hi,
    Does anyone have an idea on how to make the JTable to support column auto-maximum width resize, like we always see in a microsoft's table component, you double click on the column seperater and the column resized to its maximum size according to the content in it.
    Thanks
    Yutong

    Hi again,
    I wrote two methods to solve this kind of problem... take a look at them and tell me what you think about it...
       /** Adjusts the widths of a JTable columns
        * @param  table    the table
       public static void resizeTableColumns(JTable table) {
          table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);                    
          TableColumn c = null;
          FontMetrics fm = table.getFontMetrics(table.getFont());
          for (int i=0; i<table.getColumnCount(); i++) {
             c = table.getColumn(table.getColumnName(i));
             c.setPreferredWidth(determineColumnWidth(c, table.getModel(), fm));
       /** Returns the preferred width of a JTable column. The resulting width
        * is 5 pixels wider than the biggest column
        * @param  col    the column
        * @param  model  the table model
        * @param  fm     the font metrics
        public static int determineColumnWidth(TableColumn col, TableModel model,
                                              FontMetrics fm) {
          String value = (String)col.getHeaderValue();
          int headerWidth = fm.stringWidth("." + value.trim() + ".");
          int columnNumber = col.getModelIndex();
          int max = headerWidth;
          int columnWidth = 0;
          int nrows = model.getRowCount();
          String cell = "";
          for (int i=0; i<nrows; i++) {
             value = (String)model.getValueAt(i, columnNumber);
             columnWidth = fm.stringWidth("." + value.trim() + ".");
             if (columnWidth > max) max = columnWidth;
          return max + 5;

  • Help with JTable column width

    Hi,
    I'm trying to resize my JTable columns with this code, but it's not working. What I am doing wrong?
    for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
    TableColumn tc = table.getColumnModel().getColumn(i);
    int width = (i == 0)? 10 : table.getWidth()/2 - 10; // three columns
    tc.setPreferredWidth(width);
    Thanks,
    Andr�

    Now my problem is that using either of these methods
    is they don't carry the user's selected column width
    through updates.It sounds like the change event your table model is firing is causing the entire table to be rebuilt. I would guess that you are firing fireTableStructureChanged() which would cause the entire table to be rebuilt (columns, cell values, etc.) Just fire a change event for the minimum necessary. If you can't identify what data in your table has changed (to fire cell or row change events), but the structure (columns) of the table hasn't changed, just fire fireTableDataChanged(). This will cause the cells to be redrawn with the new values, but shouldn't cause the columns to be rebuilt and resized.

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

Maybe you are looking for