JTable width resize

Hello,
I insert a JTable without header in a JTextPane. I'm able to resize the width of the columns with the mouse, but the JTable isn't resized. I call the method JTable.setWidth(int width); to set the start width.
Do anyone knows a solution ?
Thanks in advance

Usually a JTable is added in an JScrollPane. Please use setMinimumSize() or setPreferredSize() to set this pane the size you want it to start.

Similar Messages

  • Strange JTable/JViewport resizing

    Folk'ses,
    i have a strange problem with a JTable and its viewport when i change the data and column model.
    * autoResizeMode is set to AUTO_RESIZE_ALL_COLUMNS.
    * all my columns have a minimum size
    * when i change my data and column model i do not get a scrollbar in the surrounding scrollpane
    in the 1.5 JTable.doLayout() doc i found the following note:
    Note: When a JTable makes adjustments to the widths of the columns it respects their minimum and maximum values absolutely. It is therefore possible that, even after this method is called, the total width of the columns is still not equal to the width of the table. When this happens the JTable does not put itself in AUTO_RESIZE_OFF mode to bring up a scroll bar, or break other commitments of its current auto-resize mode -- instead it allows its bounds to be set larger (or smaller) than the total of the column minimum or maximum, meaning, either that there will not be enough room to display all of the columns, or that the columns will not fill the JTable's bounds. These respectively, result in the clipping of some columns or an area being painted in the JTable's background color during painting.
    has anybody an idea how to get around this problem?
    is it so uncommon?
    why did they implement it like that?
    frustrated,
    thomas

    frustrated,Yes, a verbal description of the problem doesn't always help me. I have no idea what you code is like, what layout manger you are using etc.....
    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 (SSCCE) 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.

  • JTable column resize dilemma?

    Hi:
    I have a JTable instance jTable resides in a JScrollPane that loads data from a file. However the horizontal scroll bar does not come out even if there are way too many columns. I searched online and find out I have to do this:
    jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    Now I have another problem. Every column are the same size, even if some column clearly have longer string.
    Sure I can write an algorithm calculating suitable column width, but, is there a better way? I mean JTable's auto resizing algorithm clearly know which column should be wider but it is just a little stupid for trying to squeeze everything in a tiny space even though there is a horizontal scroll bar...
    Can't we let the JTable figure out the right width without the width constraint?
    thanks

    Can't we let the JTable figure out the right width without the width constraint?There are solutions in the forum for dynamically determining the width of a column.

  • JTable Header resizing codes ?

    Does anyone have reusable codes that can accept the column names then resize the JTable columns automatically. By using the column names width the table headers are automatically computed to column preferred size.

    Please refer to http://www2.gol.com/users/tame/swing/examples/SwingExamples.html for a possible solution.

  • 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

  • Can i set only 1 column in a jtable to resize?

    Hi,
    I want to set only the columns with "Strings" as content to be resizable inside my jtable. and leave those which are ints, as a fixed size, but I haven't been able to find a way of setting the resizing options for a specific column...
    any ideas?

    You would need to check the column number and the data type in the column being resized and force it back to a set value if it was not a column with a string in it. Remember the user can swap the columns.
    rykk

  • JTable user resize columns with grid?

    Is it possible to allow a user to resize columns not just through the table header, but with the vertical grid lines?

    There is no method that allows you to toggle this
    feature on/off if thats what you are asking.Yes, thats what I was asking.
    If you want to implement this type of functionality
    yourself then take a look at the source code for
    JTableHeader to see how its done.Thanks, I'll look into that - though it would be cool if that was already a feature of JTable.

  • JTable column resize listener

    Hi friends !
    I want to trap the event when user resizes the width of any column. Which listener will help me for this.
    Thanks in advance.
    Ramesh

    Thanks a lot camickr !!
    It worked fine !! I did it like this
    table.getColumnModel().addColumnModelListener(new TableColumnModelListener(){
         public void columnMarginChanged(ChangeEvent e)
                   // Your code goes here..     
         public void columnSelectionChanged(ListSelectionEvent e){}
         public void columnAdded(TableColumnModelEvent e){}
         public void columnMoved(TableColumnModelEvent e){}
         public void columnRemoved(TableColumnModelEvent e){}
    });Thanks a lot again !!

  • Safari fullscreen width resize

    Hello!
    In OS X Lion, with Safari 5, you could go full-screen with Safari, then resize the width of the browser by going to the left or right edge, hold the option key, and reside the width of the browser.
    I make responsive websites, so this feature is key. Can you enable that feature in Safari 7 with Mavericks?
    Thanks!

    Hi...
    Just so you are aware, you are not communicating direclty with Apple here. This is a user to user forum.
    What you can do is send feedback to Apple >  Apple - Mac OS X - Feedback
    You can resize the Safari (7) window without the Option key. Hover the cursor over the edge of the Safari window then drag.

  • JTable width

    I've got the following code:
    public class JMyFrame
    extends JFrame
      public JTable jTable;
      public JScrollPane jScrollPane;
      public JMyFrame()
        setSize(APP_WIDTH, APP_HEIGHT);
        setResizable(false);
        jTable = new JTable(...);
        jScrollPane = new JScrollPane(jTable);
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        contentPane.add(jScrollPane, BorderLayout.CENTER);   
      public static void main(String[] args)
        try {
          JFrame jFrame = new JMyFrame();
          jFrame.addWindowListener(
            new WindowAdapter()
              public void windowClosing(WindowEvent e)
                System.exit(0);
          jFrame.setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
    }I want to adjust the size of the columns depending on the avalaible width. How can I know the real avalaible width before the table is going to be shown in the screen?
    If I add the following lines of code just before the end of the JMyFrame constructor:
    System.err.println("jTable.getSize()=" + jTable.getSize());
    System.err.println("jTable.getPreferredSize()=" + jTable.getPreferredSize());
    System.err.println("jScrollPane.getSize()=" + jScrollPane.getSize());
    System.err.println("jScrollPane.getPreferredSize()=" + jScrollPane.getPreferredSize());
    System.err.println("jScrollPane.getViewport().getSize()=" + jScrollPane.getViewport().getSize());
    System.err.println("jScrollPane.getViewport().getPreferredSize()=" + jScrollPane.getViewport().getPreferredSize());I get:
    jTable.getSize()=java.awt.Dimension[width=0,height=0]
    jTable.getPreferredSize()=java.awt.Dimension[width=150,height=32]
    jScrollPane.getSize()=java.awt.Dimension[width=0,height=0]
    jScrollPane.getPreferredSize()=java.awt.Dimension[width=470,height=404]
    jScrollPane.getViewport().getSize()=java.awt.Dimension[width=0,height=0]
    jScrollPane.getViewport().getPreferredSize()=java.awt.Dimension[width=450,height=400]but neither of these values represent the real avalaible width.
    I've added a button in order to get more information after everything is displayed on the screen. When I clicked the same lines of code show totally different results:
    jTable.getSize()=java.awt.Dimension[width=150,height=32]
    jTable.getPreferredSize()=java.awt.Dimension[width=150,height=32]
    jScrollPane.getSize()=java.awt.Dimension[width=594,height=350]
    jScrollPane.getPreferredSize()=java.awt.Dimension[width=470,height=424]
    jScrollPane.getViewport().getSize()=java.awt.Dimension[width=574,height=326]
    jScrollPane.getViewport().getPreferredSize()=java.awt.Dimension[width=450,height=400]In this case, the value returned by jScrollPane.getViewport().getSize() do represent the avalaible width and height.
    I guess this happens because this way I'm getting this values after the whole applications in displayed on the screen. Is there a way to do it before?

    I doesn't work. Everytime I execute this code:
    System.err.println("jTable.getSize()=" + jTable.getSize());
    System.err.println("jTable.getPreferredSize()=" + jTable.getPreferredSize());
    System.err.println("jScrollPane.getSize()=" + jScrollPane.getSize());
    System.err.println("jScrollPane.getPreferredSize()=" + jScrollPane.getPreferredSize());
    System.err.println("jScrollPane.getViewport().getSize()=" + jScrollPane.getViewport().getSize());
    System.err.println("jScrollPane.getViewport().getPreferredSize()=" + jScrollPane.getViewport().getPreferredSize());before executing jFrame.setVisible(true) I get:
    jTable.getSize()=java.awt.Dimension[width=0,height=0]
    jTable.getPreferredSize()=java.awt.Dimension[width=150,height=32]
    jScrollPane.getSize()=java.awt.Dimension[width=0,height=0]
    jScrollPane.getPreferredSize()=java.awt.Dimension[width=470,height=404]
    jScrollPane.getViewport().getSize()=java.awt.Dimension[width=0,height=0]
    jScrollPane.getViewport().getPreferredSize()=java.awt.Dimension[width=450,height=400]But If I execute it after executing jFrame.setVisible(true) I get:
    jTable.getSize()=java.awt.Dimension[width=150,height=32]
    jTable.getPreferredSize()=java.awt.Dimension[width=150,height=32]
    jScrollPane.getSize()=java.awt.Dimension[width=394,height=97]
    jScrollPane.getPreferredSize()=java.awt.Dimension[width=470,height=424]
    jScrollPane.getViewport().getSize()=java.awt.Dimension[width=374,height=73]
    jScrollPane.getViewport().getPreferredSize()=java.awt.Dimension[width=450,height=400]and these values are the ones I'm looking for...but just before setting the visibility of the main frame to true.
    I've also tried to do the following:
    jFrame.doLayout();
    System.err.println("jTable.getSize()=" + jTable.getSize());
    System.err.println("jTable.getPreferredSize()=" + jTable.getPreferredSize());
    System.err.println("jScrollPane.getSize()=" + jScrollPane.getSize());
    System.err.println("jScrollPane.getPreferredSize()=" + jScrollPane.getPreferredSize());
    System.err.println("jScrollPane.getViewport().getSize()=" + jScrollPane.getViewport().getSize());
    System.err.println("jScrollPane.getViewport().getPreferredSize()=" + jScrollPane.getViewport().getPreferredSize());
    jFrame.setVisible(true)or
    jFrame.validate();
    System.err.println("jTable.getSize()=" + jTable.getSize());
    System.err.println("jTable.getPreferredSize()=" + jTable.getPreferredSize());
    System.err.println("jScrollPane.getSize()=" + jScrollPane.getSize());
    System.err.println("jScrollPane.getPreferredSize()=" + jScrollPane.getPreferredSize());
    System.err.println("jScrollPane.getViewport().getSize()=" + jScrollPane.getViewport().getSize());
    System.err.println("jScrollPane.getViewport().getPreferredSize()=" + jScrollPane.getViewport().getPreferredSize());
    jFrame.setVisible(true)but it doesn't work either.

  • Updates to JTables and resizing of columns

    I'm building an application that has many tables that all use table models that I have created. All of the table models extend DefaultTableModel. Before entering any data in the tables i set the size of the columns. Below is an example of how I do this...
          //tcm = table column model
          tcm.getColumn(0).setPreferredWidth(100);
          tcm.getColumn(1).setPreferredWidth(100);
          tcm.getColumn(2).setPreferredWidth(100);
          tcm.getColumn(3).setPreferredWidth(100);
          tcm.getColumn(4).setPreferredWidth(172);
          tcm.getColumn(5).setPreferredWidth(172);
          My problem is everytime I update the table with new data the columns keep adjusting themselves to the width of the largest piece of data in the particular column. In order to keep the size of the columns I want I've been resizing the columns with the above code everytime I update the table. Can someone tell me how to set the column sizes once and have them remain that way?

    I'm sorry to hear that you're having problems customising your Spotify for Mac application. I'm sure Spotify do value your custom and will take your suggestion to return this feature. For now, I think posting your idea in the Ideas forum would be best to get your idea out there and upvoted by fellow community members wishing for the return of this feature. You can submit your idea at: https://community.spotify.com/t5/forums/postpage/board-id/ideas_submissions Take care and let me know how it goes!

  • JTable header resizing problame.

    Hi All,
    I am using one JTabl with table header and i want to give resizing to all selected header column when any one one of them getResized by mouse dragging (just like EXCEL sheet)
    is it possible ??
    Any body can suggest some example or any tips on this.
    thanx in advance.
    == Gavin

    Any body can suggest some example or any tips on this.You where given a "tip" 6 days ago when you asked the same question:
    http://forum.java.sun.com/thread.jspa?threadID=582056&messageID=2962393

  • Calendar cell width resizing

    I want to resize the calendar cell width and height ? b'coz my calendar column value is huge(also i use custom option to display more than 2 columsn in the calendar column value).
    I used Apex 3.2
    Browser: IE 7
    I tried changing the the seetings in Edit Page --> Item --> PX_CALENDAR_TYPE or PX_CALENDAR_DATE (hidden), but it doesnt affect my calendar cell spacing .....
    Could any one please help on this ...
    Regards,
    Manoj
    Edited by: 882468 on Nov 14, 2011 4:58 PM

    Hello Manish,
    The report column width will adjust depending your content.
    In the html expression of your column definition you can wrap it in a div or span and specify for ex. style="overflow: auto; width: 100px;"
    Hope that makes sense.
    Regards,
    Dimitri
    -- http://dgielis.blogspot.com/
    -- http://apex-evangelists.com/
    -- http://apexblogs.info/

  • Width Resize

    Hi All,
    Please help for my Very Urgent Request....
    I need to change the width of the image into 85 mm. I dont know why the below coding is not working for me
    Trying Code 1:
    app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;
    app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;
    parseInt(app.selection[0].geometricBounds[3] - app.selection[0].geometricBounds[1]) = 85;
    Trying code 2:
    var myGraphics = app.activeDocument.allGraphics;
    alert(myGraphics.length)
    for(i=0; i<myGraphics.length; i++)
       app.select(myGraphics[i].parent);
        var myGBounds = myGraphics[i].parent.geometricBounds;
        myGraphics[i].parent.geometricBounds = [myGBounds[0], myGBounds[1], myGBounds[2], myGBounds[3]+20]
    Input Screenshot: (Look at the Width)
    Output Screenshot: (Look at the width)
    Regards
    Siraj

    Try the below code (simple way), you please proceed further...
    var gBounds = app.selection[0].geometricBounds;//select your image
    app.selection[0].geometricBounds = [gBounds[0], 57.5, gBounds[2], 142.5]
    app.selection[0].fit(FitOptions.frameToContent);
    Vandy

  • Resizing columns in a JTable in a JScrollpane

    I have a JTable in a JScrollpane and I after I load the table, I resize the columns to fit the data (works well).
    The problem is that I want the scrollpane to stay the same size and let the table scroll horizontally inside the viewport. The actual result is the scrollpane stretches to the width of the table causing the user to scroll the panel rather than the scrollpane.
    I've tried setting the scrollbar policy but that didn't work.

    I am passing the JTable to the constructor of the JScrollPane.
    I have a JTable in a JScrollPane that sits on a JPanel which is in a JScrollPane itself.
    After I load the data into the JTable, I resize all of the columns to fit the data.
    The problem is that the JTable resizes wider than original size causing the whole panel to scroll horizontally. I would rather have the JScrollPane that the JTable is in scroll.

Maybe you are looking for