User cannot resize jTables� columns

Hello,
Using NetBeans IDE 3.5.1, I built a jTable, controlled by a
JScrollpane.
My problem is that the user cannot resize the jTables� columns.
Maximum details:
1.     jtablewidth is set to a fixed value according to internal data:
JTable1.setPreferredSize( new Dimension(tableWidth, i_TableHeight));
2.     columnwidth is set according to internal data:
Col = JTable1.getColumnModel().getColumn(i);
Col.setWidth(width);
Col.setResizable(true);
Col.setMinWidth(width);
3.     jTable header details:
JTableHeader anHeader = JTable1.getTableHeader();
anHeader.setReorderingAllowed(false);
anHeader.setResizingAllowed(true);
4.     JTable1.getTableHeader().setResizingAllowed(true);.
5.     Initial declerations:
a.     JTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
     JTable1.setColumnSelectionAllowed(true);
     JTable1.setDragEnabled(true);
     JTable1.setPreferredScrollableViewportSize(new
java.awt.Dimension(650, 500));
     JTable1.setPreferredSize(new java.awt.Dimension(1200, 409));
     JTable1.setRequestFocusEnabled(false);
b.     JScrollPane1.setMaximumSize(new java.awt.Dimension(750, 412));
     JScrollPane1.setPreferredSize(new java.awt.Dimension(750,
412));
     JScrollPane1.setViewportView(JTable1);
     JScrollPane1.setAutoScolls(false);
c.     Jtable.autoCreateColumnsFromModel (true);
Thanks alot,
Itay

Columns resizing works by default. You don't need to do anything special.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Similar Messages

  • Resize JTable Columns without Column Header

    Hi all.
    I have a JTable that doesn't display a column header.
    I would like to allow the user to resize the columns by dragging a mouse at the column edges at any point down the table.
    It is not obvious how I can accomplish this.
    Does anyone have any ideas?
    Thanks, Paul.

    That doesn't work, though, since the table has its own listenersIt's not just that. The header's mouse listeners work with instance fields of BasicTableHeaderUI and detection (using e.getPoint) of the header cell and column.
    I would start with copying the entire code of BasicTableHeaderUI to a class of my own, then first eliminate anything that obviously isn't related to column dragging/resizing, then refactor, refactor, refactor to make the listener codes work with a table instead of a header. But like I said, easier said than done, particularly when having to deal with the various JTable column resize modes.
    db

  • Cannot resize some columns in the music folder for my ipod

    It seems I cannot resize some of the columns I'm displaying in the music folder for my iPod... such as:
    Album, Grouping, Kind
    But I can resize the other columns...
    I've tried moving the column around, doesn't seem to help
    I can resize all columns in my Music folder for the PC.
    Any ideas?!?

    ok...
    If I remove the column from my view... and then re-add the column, it all works fine.
    Is this a bug?

  • How to resizea JTable column to fit to text programatically?

    hi evreyone,
    i'm trying to resize a JTable column width to fit to the contained text programatically.my approach was that i made a comparison between the length of String objects contained in my column and got the biggest String length value but i want to know how can i resize the column to fit to this biggest String object

    You're going the wrong way about it - don't go calculating string lengths. Get the TableCellRenderer, query it for the renderer component for each cell in the column, obtain its preferred size and keep a record of the greatest width value.

  • Resize JTable columns by double-clicking header

    I want to implement column resizing in a JTable so that when the user double clicks on the column header with the mouse in the "resize zone" the column automatically adjusts to the width of the longest text in the column. this is how many applications behave (e.g. windows explorer) but I don't think I've ever seen a swing app that does this. I've looked in the API docs for JTable and JTableHeader and I can't see any way of finding out if the mouse is over the edge of a column header. does anyone know of a way to do this?

    Is this laf independant?import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Test extends JFrame {
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One","Two","Three"};
        String[][] data = {{"R1-C1","R1-C2","R1-C3"},
                {"R2-C1","R2-C2","R2-C3"},
                {"R3-C1","R3-C2","R3-C3"}};
        JTable jt = new JTable(data, head);
        JScrollPane jsp = new JScrollPane(jt);
        content.add(jsp, BorderLayout.CENTER);
        JTableHeader jth = jt.getTableHeader();
        jth.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            JTableHeader jth = (JTableHeader)me.getSource();
            int col = jth.columnAtPoint(me.getPoint());
            Rectangle r = jth.getHeaderRect(col);
            if (jth.getCursor().equals(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR))) {
              System.out.println("Cursor, col="+col);
        setSize(300, 300);
        setVisible(true);
      public static void main(String args[]) { new Test(); }
    }

  • 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

  • Jtable column resize

    Hi all!
    i'm using:
    jTable1.getColumnModel().getColumn(1).setPreferredWidth(7);     
    to resize jtable column width but it's not working, do you know what can be happening?
    thanks!

    All you've done is say what size you would prefer.
    You then have to force the component to repaint, with something like
                jTable1.invalidate();
                jTable1.doLayout();
                jTable1.repaint();Ps. I posted a nice utility class to automaticaly fit the JTable columns to the exact size required here.
    http://forum.java.sun.com/thread.jspa?forumID=54&messageID=2532529&threadID=527301
    regards,
    Owen

  • Dynamically resize JTable cell to fit a JList

    Hi!
    I've been banging my head trying to add some dynamic behavior to a TableCellEditor. In short I'm trying trying to make it resize the height of the current row (the one it is in) to reflect the changes made to the JList used to let the user edit the cells value (which is a list of items).
    I've come across some threads dealing with the problem of resizing a cell to fit its content. This however is usually only done once (in the 'getTableCellEditorComponent' function) and so only provides half the answer. Also, since the editor is only active during cell editing I've been trying to make it revert to the old cell height after the editing is done.
    So far I have not come up with any decent solution to this problem and was hoping someone out there might have an idea or have read something similar and can point me to something helpful... anyone?
    Cheers!
    Teo

    The Swing tutorial on[url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html]How to Use Tables shows how to dynamically change the size to Table Columns.
    If you need help calculating the acutal size then try searching the forum. Using keywords "resize jtable column" (keywords I took directly from your topic title) I found some promising postings.

  • Resize JTable that doesn't include header

    hi all
    I want to insert the table that is not include header and want to allow the user to resize the column
    thanx

    You already asked the same question in this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=526540]post.
    Don't clutter the forum by asking the same question over and over again. You won't get an answer faster.

  • ALV : forbid resizing of columns

    Hi,
    in my ALV i would like to forbid to users the resizing of columns. How can i do that ?
    Thanks a lot.

    Hi,
    Standard authorization object S_ALV_LAYO can be used to control user access for globally
    changing the ALV report layouts.
    Hope this will help you.
    Thanks&Regards

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

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

  • How to listen for resizing of JTable column

    Is there anyway to tell when the columns in a JTable are being resized by the user? I couldn't find any listeners or anything that will tell you when the user is dragging the column width with the mouse.
    Thanks.

    Use ColumnModelListener as shown below:-
              table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {
                   public void columnAdded(TableColumnModelEvent e) {
                   public void columnMoved(TableColumnModelEvent e) {
                   public void columnRemoved(TableColumnModelEvent e) {
                   public void columnMarginChanged(ChangeEvent e) {
                   public void columnSelectionChanged(ListSelectionEvent e) {
              });

  • Is it possible to resize page column widths at runtime (by the user)?

    hi all,
    i have cretaed a page using the 2-columns narrow/wide layout.  this layout is perfect for what i want to do.
    however, the users have complained that they would like to be able to resize the columns, just like they are able to do with the Detailed Navigation column (using the small "<" and ">" arrows).
    is it posssible to add this functionality to my custom pages so that can also resize the columns?
    i searched for options in the properties, but didn't find anything.
    thanks,
    mm

    This was a great place for me to start
    Thank you
    I took profdant139's suggestions a bit further as my real goal was to have the "Document column" narrower. The goal to be able to see all the other document info that was usually hidden way out to the right
    To achieve my results I right clicked in the upper bar with the column names and chose from the drop down box "comments" column (as suggested). I then dragged it to the far right. This pushed all the other columns over.
    In the end of the day I ended up adding "Size" and "Date modified" columns as well to get my desired results.
    Remember one can move different columns around to be in the order you need by clicking on the column to get it active and then left click and drag it to where you want
    Another great thing is that by default (Using Mavericks) the date modified, opened,created columns have date and time. One can shrink them down to xx/xx/xx format by manually adjusting the column width like one does in Excel - click on column separator up top and drag
    Once all that is done, at least on my box, I closed it out and opened up a new finder window and everything was as I wanted.
    Thank you for the help  from the above helper to get me here

  • Lion Finder "Find" command window, cannot resize columns

    If I use the Finder's "Find.." command under the File menu, a window appears that allows me to enter my serach criteria.
    However when I do so and a list of entries is presented, there appears to be no way to resize the columns!
    Als, unlike a normal Finder window, it does not present you with column headings that you can sort on (yes, you can still access this level of control by going to "Show View Options".
    Try it. I know that a normal Finder window allows you to do this, but not a "Find" window.
    I have no idea why they use a different design style for the "Find" results window. The standard Finder list view window at least has the proper controls on it (ability to resize, ability to slect which column to sort upon, ability to slect sort order up or down, etc.)
    Any ideas as to how to fix these problems?

    David.
    You'll need to select View>Arrange By>None to get the ability to adjust columne width.
    You can also get at it by clicking the little gear icon in the tool bar.
    Matt

Maybe you are looking for

  • How can I recover my back up data?

    I back up data on iTunes (iPhone 5) And I accidentally deleted some files on iTunes and iPhoto folder. (I don't know it is the back up folder) Now I found out that my application are all grey, they don't show the image of the apps. I also imported al

  • Access blob storage files by specific domain. (Prevent hotlinking in Azure Blob Storage)

    Hi, My application deployed on azure, and I managed all my file to blob storage. When i created container with public permission then it accessible for all anonymous users. When i hit URL of file (blob) from different browser, then i will get that fi

  • Using an Apple Wireless Keyboard with a Windows PC

    Hey, I know that this has been posted up before but i have read through the threads and followed the various instructions and i am still not getting any results. I am using a Belkin USB Bluetooth device (Model F8T013) and when it all seems like it's

  • IPhone Shutting Off When In Sleep Mode

    So, I had a problem with my iphone, and took it to the mac store and got it replaced. now, my new iphone will completely shut down within minutes of being in sleep mode. it will only stay on in sleep mode when it's connected to power. is there any wa

  • DTP Born with Incorrect Real-Time Status

    Hi Gurus, What am I doing wrong? When I create a DTP for Real-Time Acquisition, I am getting "Real-Time Status" as "Incorrect" even with a DTP Type correctly set for Real-Time. I have no option to change it for following status: - New, Without Data P