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.

Similar Messages

  • Strange JTable behaviour - everything is highlighted

    Hello all,
    im experiencing some strange JTable behaviour, and im not so sure why. When i run my program, the JTable appears, but all the cells are highlighted in advance. Also, i can now only select one cell at a time. I have set myTable.setSelectionModeListSelectionModel.SINGLE_INTERVAL_SELECTION);  myTable.setCellSelectionEnabled(true);and my renderer code is below. I call the renderer by using the setDefaultRenderer method with(Object.class,myRenderer).
    I have also changed isCellEditable to return true. If i dont use Object.class, and try to use my own custom class, the JTable is not all highlighted, but it doesnt seem to use myRenderer, and when i click on the header of Column A, all cells from column B and beyond become highlight, which is not normal behaviour. I thought the colum you selected should be highlighted.
    Sorry for the long post, i hope the above makes sense...this is really quite bizzare, and im not so sure why this is happening. Thanks for any advice you can give, regards, Rupz
    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.border.*;
    import java.awt.Component;
    import java.awt.Color;
    import java.awt.Rectangle;
    import java.util.*;
    import java.awt.*;
    public class MyTableCellRenderer extends DefaultTableCellRenderer{
         private Font cellFont;
         private LineBorder  selectBorder;
        private EmptyBorder emptyBorder;
         public MyTableCellRenderer() {
              super();
              setOpaque(true);
              emptyBorder  = new EmptyBorder(1, 2, 1, 2);
              cellFont = new Font("Times", Font.PLAIN, 10);
              setFont(cellFont);
              selectBorder = new LineBorder(Color.red);
         private boolean isHeaderCell(int row, int column){return column == 0;}
         public Component getTableCellRendererComponent (JTable myTable, Object value, boolean isSelected, boolean hasFocus, int row, int column){
              //super.getTableCellRendererComponent(myTable, value, isSelected, hasFocus,row, column);
              if (isSelected){
                   super.setForeground(myTable.getSelectionForeground());
                   super.setBackground(myTable.getSelectionBackground());
                   setBorder(selectBorder);
              else{
                   super.setForeground(myTable.getSelectionForeground());
                   super.setBackground(myTable.getSelectionBackground());
                   setBorder(emptyBorder);
         if (hasFocus) {
              setBorder(selectBorder);
              if (myTable.isCellEditable(row,column)) {
                   super.setForeground(UIManager.getColor("Table.focusCellForeground"));
                   super.setBackground(UIManager.getColor("Table.focusCellBackground"));
         else {setBorder(noFocusBorder);}
         setValue(value, isSelected, hasFocus, row, column);
    //      Color bDis = getBackground();
    //      boolean colourEquals = (bDis != null) && (bDis.equals(myTable.getBackground()) ) & myTable.isOpaque();
    //      setOpaque (!colourEquals);
         return this;
         public void setValue (Object value, boolean hasFocus, boolean isSelected, int row, int column){
              if (value instanceof myCell){
                   myCell foo = (myCell)value;
                   Object data = foo.getValue(row,column);
                   if (isHeaderCell(row, column)) {
                    //label cells are center aligned
                        setHorizontalAlignment(JTextField.CENTER);
                       }else {
                              if (data instanceof Number) {
                                  //numbers are right justified
                            setHorizontalAlignment(JTextField.RIGHT);
                              }else {
                                  //everything else is left justified
                            setHorizontalAlignment(JTextField.LEFT);
                          //value to display in table
                       setText((data == null) ? "" : data.toString());
               else {
                          //not cell object so render with toString of that object
                          setText((value == null) ? "" : value.toString());

    Hi VV!
    thanks for the reply - now the table isnt all highlight when loaded, but as for cell celection..thats a different matter. I did have myTable.setCellSelectionEnabled(true); but no, the cell behaviour is really, eally weird, quite hard to explain, but here goes.
    If i try to select cell D1 and D2 - D1 is selected, D2, E2,F2 and so on become selected. If i try to add D3 to the mix, the entire row 3 is selected, and as soon as i let go of the mouse button, the entire table except row 1 gets selected. really really weird. Below is my tableModel and what i do to the table. Thanks for your help,
    regards
    Rupz
    myTable.setModel(new myTableModel(this,40,40));
         // Create a row-header to display row numbers.
         // This row-header is made of labels whose Borders,
         // Foregrounds, Backgrounds, and Fonts must be
         // the one used for the table column headers.
         // Also ensure that the row-header labels and the table
         // rows have the same height.
         numRows = myTable.getColumnCount();
         numCols = myTable.getRowCount();
         TableColumn       aColumn   = myTable.getColumnModel().getColumn(0);
         TableCellRenderer aRenderer = myTable.getTableHeader().getDefaultRenderer();
         Component aComponent = aRenderer.getTableCellRendererComponent(myTable, aColumn.getHeaderValue(), false, false, -1, 0);
         Font  aFont       = aComponent.getFont();
         Color aBackground = aComponent.getBackground();
         Color aForeground = aComponent.getForeground();
         Border      border  = (Border)UIManager.getDefaults().get("TableHeader.cellBorder");
         FontMetrics metrics = getFontMetrics(cellFont);
          * Creating a panel to be used as the row header.
          * Since I'm not using any LayoutManager,
          * a call to setPreferredSize().
         JPanel pnl = new JPanel((LayoutManager)null);
         Dimension dim = new Dimension( 40,  rowHeight*numRows);
         pnl.setPreferredSize(dim);
         // Adding the row header labels
         dim.height = rowHeight;
         for (int ii=0; ii<numRows; ii++) {
           JLabel lbl = new JLabel(Integer.toString(ii+1), SwingConstants.CENTER);
           lbl.setFont(aFont);
           lbl.setBackground(aBackground);
           lbl.setForeground(aForeground);
           lbl.setBorder(border);
           lbl.setBounds(0, ii*dim.height, dim.width, dim.height);
           pnl.add(lbl);
         JViewport vp = new JViewport();
         dim.height = rowHeight*numRows;
         vp.setViewSize(dim);
         vp.setView(pnl);
         // Set resize policy and make sure
         // the table's size is tailored
         // as soon as it gets drawn.
         myTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
         Dimension dimScpViewport = myTable.getPreferredScrollableViewportSize();
         if (numRows>30) dimScpViewport.height = 30*rowHeight;
         else           dimScpViewport.height  = numRows*rowHeight;
         if (numCols>15)
           dimScpViewport.width = 15*myTable.getColumnModel().getTotalColumnWidth()/numCols;
         else
           dimScpViewport.width = myTable.getColumnModel().getTotalColumnWidth();
         myTable.setPreferredScrollableViewportSize(dimScpViewport);
         myTable.repaint();
    And the table model
    public class myTableModel extends DefaultTableModel {
         private MySpread mySpreadsheet;
         public myTableModel (MySpread aSpreadsheet){
              super();
              mySpreadsheet = aSpreadsheet;
         public myTableModel (MySpread aSpreadsheet, int rows,int cols){
              super(rows,cols);
    //                 for(int x = 0; x < rows; x++) {
    //                      myCell temp = new myCell(new Integer(x+1));
    //                  super.setValueAt(temp, x, 0);
            for(int x =0 ; x < rows; x++)
             for (int y = 0; y < cols; y++)
              // we initialize it here
              super.setValueAt(new myCell(rows,cols,("")),x,y);
         mySpreadsheet = aSpreadsheet;
         public boolean isCellEditable(int row, int column) {return true;}  
         

  • JViewport Resize problem -- Urgent!

    I am trying to make a program that allows the user to dynamically resize a scrollable JPanel. I have added resize buttons that work well. The JScrollPane works well, but when the JViewport's View is set to the bottom right corner of the JPanel, and the user attempts to resize the JPanel, the JViewport repaints its view to the top left corner, hence undoing any resizing. Resizing should not change the View, even if the component is no longer visible in the view.
    Here is a code example (please pardon the length and lack of comments):
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    public class JViewportBug extends JPanel implements Scrollable, ComponentListener
         public JViewportBug()
              this.setLayout( null );
         public Dimension getPreferredScrollableViewportSize()
              return getPreferredSize();
         public boolean getScrollableTracksViewportHeight()
              return false;
         public boolean getScrollableTracksViewportWidth()
              return false;
         public int getScrollableBlockIncrement( Rectangle visibleRect, int orientation, int direction )
              if( orientation == SwingConstants.VERTICAL )
                   return (int)( visibleRect.getHeight() * 9 / 10 );
              return (int)( visibleRect.getWidth() * 9 / 10 );
         public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction )
              return 5;
         public void componentHidden(ComponentEvent e)
         public void componentMoved(ComponentEvent e)
         public void componentResized(ComponentEvent e)
              Dimension size = ( (Component)e.getSource() ).getSize();
              this.setBounds( 0, 0, 20 + size.width, 20 + size.height );
              this.setPreferredSize( new Dimension( 20 + size.width, 20 + size.height ) );
         public void componentShown(ComponentEvent e)
         public static void main( String[] args )
              JViewportBug bug = new JViewportBug();
              JFrame frame = new JFrame( "JViewport Bug" );
              frame.setExtendedState( JFrame.MAXIMIZED_BOTH );
              JScrollPane jsp = new JScrollPane( bug );
              JPanel viewable = new JPanel();
              bug.add( viewable );
              viewable.addComponentListener( bug );
              viewable.setBounds( 10, 10, 200, 200 );
              JDesktopPane jdp = new JDesktopPane();
              jdp.setLayout( null );
              for( int i = 0; i < 8; i++ )
                   ResizeButton rb = new ResizeButton( viewable, i, true );
                   bug.add( rb );
                   viewable.addComponentListener( rb );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              viewable.setBackground( Color.white );
              frame.getContentPane().add( jdp, BorderLayout.CENTER );
              JInternalFrame jif = new JInternalFrame( "", true, true, true, true );
              jif.getContentPane().add( jsp );
              jdp.add( jif );
              jif.setSize( 500, 500 );
              bug.setPreferredSize( new Dimension( viewable.getWidth() + 20, viewable.getHeight() + 20 ) );
              jif.setVisible( true );
              frame.setVisible( true );
    class ResizeButton extends JComponent implements MouseMotionListener, MouseListener, ComponentListener
         public static final int NW_RESIZE_BUTTON = 0;
         public static final int N_RESIZE_BUTTON = 1;
         public static final int NE_RESIZE_BUTTON = 2;
         public static final int E_RESIZE_BUTTON = 3;
         public static final int SE_RESIZE_BUTTON = 4;
         public static final int S_RESIZE_BUTTON = 5;
         public static final int SW_RESIZE_BUTTON = 6;
         public static final int W_RESIZE_BUTTON = 7;
         JComponent resize;
         int buttonType;
         boolean enabled;
         public ResizeButton( JComponent aComponent, int type, boolean isEnabled )
              resize = aComponent;
              buttonType = type;
              setBounds();
              enabled = isEnabled;
              this.addMouseMotionListener( this );
              this.addMouseListener( this );
         public int getType()
              return buttonType;
         public void mouseEntered( MouseEvent e )
              if( enabled )
                   switch( ( (ResizeButton)e.getSource() ).getType() )
                        case 0:
                             getParent().setCursor( new Cursor( Cursor.NW_RESIZE_CURSOR ) );
                             break;
                        case 1:
                             getParent().setCursor( new Cursor( Cursor.N_RESIZE_CURSOR ) );
                             break;
                        case 2:
                             getParent().setCursor( new Cursor( Cursor.NE_RESIZE_CURSOR ) );
                             break;
                        case 3:
                             getParent().setCursor( new Cursor( Cursor.E_RESIZE_CURSOR ) );
                             break;
                        case 4:
                             getParent().setCursor( new Cursor( Cursor.SE_RESIZE_CURSOR ) );
                             break;
                        case 5:
                             getParent().setCursor( new Cursor( Cursor.S_RESIZE_CURSOR ) );
                             break;
                        case 6:
                             getParent().setCursor( new Cursor( Cursor.SW_RESIZE_CURSOR ) );
                             break;
                        case 7:
                             getParent().setCursor( new Cursor( Cursor.W_RESIZE_CURSOR ) );
         public void mouseExited( MouseEvent e )
              if( enabled )
                   getParent().setCursor( new Cursor( Cursor.DEFAULT_CURSOR ) );
         public void mouseClicked( MouseEvent e )
         public void mousePressed( MouseEvent e )
         public void mouseReleased( MouseEvent e )
         public void mouseMoved( MouseEvent e )
         public void mouseDragged( MouseEvent e )
              if( enabled && e.getSource() instanceof ResizeButton )
                   int clickedX = e.getX();
                   int clickedY = e.getY();
                   int width, height;
                   switch( ( (ResizeButton)e.getSource() ).getType() )
                        case NW_RESIZE_BUTTON:
                             width = resize.getX() + resize.getWidth() - this.getX() - clickedX > 1 ? resize.getX() - this.getX() - clickedX + resize.getWidth() : 1;
                             height = ( resize.getY() + resize.getHeight() - this.getY() - clickedY > 1 ? resize.getY() - this.getY() - clickedY + resize.getHeight() : 1 );
                             resize.setBounds( resize.getX() + resize.getWidth() - this.getX() - clickedX > 1 ? this.getX() + clickedX : resize.getX() + resize.getWidth() - 1,
                                                           resize.getY() + resize.getHeight() - this.getY() - clickedY > 1 ? this.getY() + clickedY : resize.getY() + resize.getHeight() - 1,
                                                           width,
                                                           height );
                             break;
                        case N_RESIZE_BUTTON:
                             height = resize.getY() + resize.getHeight() - this.getY() - clickedY > 1 ? resize.getY() - this.getY() - clickedY + resize.getHeight() : 1;
                             resize.setBounds( resize.getX(),
                                                           resize.getY() + resize.getHeight() - this.getY() - clickedY > 1 ? this.getY() + clickedY : resize.getY() + resize.getHeight() - 1,
                                                           resize.getWidth(),
                                                           height );
                             break;
                        case NE_RESIZE_BUTTON:
                             width = this.getX() + clickedX - resize.getX() > 1 ? this.getX() + clickedX - resize.getX() : 1;
                             height = resize.getY() + resize.getHeight() - this.getY() - clickedY > 1 ? resize.getY() - this.getY() - clickedY + resize.getHeight() : 1;
                             resize.setBounds( resize.getX(),
                                                           resize.getY() + resize.getHeight() - this.getY() - clickedY > 1 ? this.getY() + clickedY : resize.getY() + resize.getHeight() - 1,
                                                           width,
                                                           height );
                             break;
                        case E_RESIZE_BUTTON:
                             width = this.getX() + clickedX - resize.getX() > 1 ? this.getX() + clickedX - resize.getX() : 1;
                             resize.setBounds( resize.getX(),
                                                           resize.getY(),
                                                           width,
                                                           resize.getHeight() );
                             break;
                        case SE_RESIZE_BUTTON:
                             width = this.getX() + clickedX - resize.getX() > 1 ? this.getX() + clickedX - resize.getX() : 1;
                             height = this.getY() + clickedY - resize.getY() > 1 ? this.getY() + clickedY - resize.getY() : 1;
                             resize.setBounds( resize.getX(),
                                                           resize.getY(),
                                                           width,
                                                           height );
                             break;
                        case S_RESIZE_BUTTON:
                             height = this.getY() + clickedY - resize.getY() > 1 ? this.getY() + clickedY - resize.getY() : 1;
                             resize.setBounds( resize.getX(),
                                                           resize.getY(),
                                                           resize.getWidth(),
                                                           height );
                             break;
                        case SW_RESIZE_BUTTON:
                             width = resize.getX() + resize.getWidth() - this.getX() - clickedX > 1 ? resize.getX() - this.getX() - clickedX + resize.getWidth() : 1;
                             height = this.getY() + clickedY - resize.getY() > 1 ? this.getY() + clickedY - resize.getY() : 1;
                             resize.setBounds( resize.getX() + resize.getWidth() - this.getX() - clickedX > 1 ? this.getX() + clickedX : resize.getX() + resize.getWidth() - 1,
                                                           resize.getY(),
                                                           width,
                                                           height );
                             break;
                        case W_RESIZE_BUTTON:
                             width = resize.getX() + resize.getWidth() - this.getX() - clickedX > 1 ? resize.getX() - this.getX() - clickedX + resize.getWidth() : 1;
                             resize.setBounds( resize.getX() + resize.getWidth() - this.getX() - clickedX > 1 ? this.getX() + clickedX : resize.getX() + resize.getWidth() - 1,
                                                           resize.getY(),
                                                           width,
                                                           resize.getHeight() );
         public void setBounds()
              switch( buttonType )
                   case NW_RESIZE_BUTTON:
                        this.setBounds( resize.getX() - 5,
                                                 resize.getY() - 5,
                                                 5,
                                                 5 );
                        break;
                   case N_RESIZE_BUTTON:
                        this.setBounds( (int)( ( resize.getWidth() + 2 * resize.getX() ) / 2 ) - 2,
                                                 resize.getY() - 5,
                                                 5,
                                                 5 );
                        break;
                   case NE_RESIZE_BUTTON:
                        this.setBounds( resize.getWidth() + resize.getX(),
                                                 resize.getY() - 5,
                                                 5,
                                                 5 );
                        break;
                   case E_RESIZE_BUTTON:
                        this.setBounds( resize.getWidth() + resize.getX(),
                                                 (int)( ( resize.getHeight() + 2 * resize.getY() ) / 2 ) - 2,
                                                 5,
                                                 5 );
                        break;
                   case SE_RESIZE_BUTTON:
                        this.setBounds( resize.getWidth() + resize.getX(),
                                                 resize.getHeight() + resize.getY(),
                                                 5,
                                                 5 );
                        break;
                   case S_RESIZE_BUTTON:
                        this.setBounds( (int)( ( resize.getWidth() + 2 * resize.getX() ) / 2 ) - 2,
                                                 resize.getHeight() + resize.getY(),
                                                 5,
                                                 5 );
                        break;
                   case SW_RESIZE_BUTTON:
                        this.setBounds( resize.getX() - 5,
                                                 resize.getHeight() + resize.getY(),
                                                 5,
                                                 5 );
                        break;
                   case W_RESIZE_BUTTON:
                        this.setBounds( resize.getX() - 5,
                                                 (int)( ( resize.getHeight() + 2 * resize.getY() ) / 2 ) - 2,
                                                 5,
                                                 5 );
         public void componentHidden(ComponentEvent e)
         public void componentMoved(ComponentEvent e)
         public void componentResized(ComponentEvent e)
              this.setBounds();
         public void componentShown(ComponentEvent e)
         public void setEnabled( boolean enable )
              enabled = enable;
         public boolean isEnabled()
              return enabled;
         public void paint( Graphics g )
              ( (Graphics2D)g ).fillRect( 0, 0, 5, 5 );
    }

    Hi bbritta,
    Thanks for the time. I guess the setLocation MIGHT be off, tho ideally, it should place the tv somewhere near the right bottom corner of the screen.
    The basic requirement I have is in the code written. This is what I want. When I start my application, I want the small tv screen only to appear, with the two colored panels (that shall obviously contain some other code). When my mouse hovers on this small screen, the buttons should appear in a panel just below the small screen. So I have used a JLayered pane that displays two separate gifs, one for the small screen, and one for the buttons panel. On the small screen gif, I have added two panels to layer 1, and on the button panel gif, I have added 3 buttons.
    What is happening is that if I set the frame size to the size of the small screen at startup (before show()), then on mouse hover, the frame size increases, but the layered pane size stays the same, and hence i cannot see the button panel. But if I start out with the button panel showing (frame size initially set to the larger value), then on mouse exit, the button panel disappears, and reappears properly on mouse enter. But I don't want to set the original size to the larger value, since only the small screen must be seen first.
    Did I make my self clear? The whole problem is that on mouse hover, u cannot see the button panel, till u change the setSize() code in initializeFrame() to use c_o_FULL_TV_SIZE instead of c_o_TV_SIZE. That u cannot see the buttons IS my problem!
    Thanks,
    Shefali.

  • 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

  • Strange JTable update problems

    I am having some strange issues with a JTable.
    I have a custom AbstractTableModel that displays various properties of a list of Objects. I am using a java.util.Vector to store this list.
    The user is given several JComboBox objects which contain filters for my table, when any of these filters are changed, a class that manages my Database is asked to return a Vector full of objects that match these filters.
    I then set my table data Vector equal to this returned list and invoke fireTableStructureChanged() from my table model. This part works fine, the strange thing is, if the user has a table element selected and then they change the filters, the table will not update, it actually goes blank, but oddly enough the scroll bar on the scroll pane stays the same length as the old table.
    When I invoke the exact same update method again (which just sets the Vector containing my data to a new value, and fires the event) the table will update this time.
    I have tried calling MyJTable.getSelectionModel().clearSelection() in the hope that it will fix my problem, but it does not seem to do anything.
    So is my problem some strange event or threading glitch, or an issue with JScrollPane mabye?
    Thanks in advance for any help

    Try using the DefaultTableModel to see if you have the same problem. If not then you know the problem is with your custom TableModel.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
    see http://homepage1.nifty.com/algafield/sscce.html,
    that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.

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

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

  • Strange behavior when resizing with 'Selection Tool'

    Hello,
    I have a really strange issue when using selection tool to resize object. I have several rectangles stacked and grouped inside a layer. When I select one of them (either in Layer panel or with Group selection tool) and switch to 'Selection Tool (V)' to resize it, this tool behaves diferently at diferent zoom levels. Only at 200% zoom it behaves as it shoul.. With 100-150% zoom result is diferent - like there's a invisible box around selected object and I'm resizing it.. I've tried to explain the issue in attached image.. Anyone knows why is this happening?
    Thanks.

    - make new document, size 16383x16383px
    - create rectangle any width, hight say 200px (or anything less then 320px for 5% zoom)
    - select rectangle and show bounding box
    - try resizing hight by stretching bounding box
    - this is how same selection looks at diferent zoom levels
    - same zoom level as befor, hight 100px..

  • 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

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

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

  • Strange JTable header behaviour

    Hi Guys,
    I tried to find an answer to that one, yet thing came up...
    I am creating a table using a table model with all the data. For some reason all the headers in the table are thin... I mean their height is very short, I see the header's test, but it is somewhat shinked in the short (in terms of hight) header.
    Am I missing something here??? :o)
    Here is the code for adding the headers:
    table creation.....
    //header creation
    for (int i = 0; i < tableModel.colsData.length; i++) {
        TableCellRenderer renderer;
        if (i == 0) {
            renderer = new RowHeaderRenderer(this);
        else{
            DefaultTableCellRenderer defRenderer = new DefaultTableCellRenderer();
            defRenderer.setHorizontalAlignment(tableModel.colsData.align);
    renderer = defRenderer;
    TableColumn col = new TableColumn(i, tableModel.colsData[i].width,
    renderer, null);
    addColumn(col);
    super.configureEnclosingScrollPane();

    Me again,
    It turns out that the fact that the first column header was an empty String derermined the height of the header cells to be very short.
    Thanks,
    David.

Maybe you are looking for

  • How do I connect to one computer to another?

    Hi, I had to buy a new computer, with Lion OS last July. Then someone put a new hard drive into my old computer, as SnowLeopard. Every time I do one thing on the SL computer, something else gets lost - & I have to reconfigure stuff. Some things won't

  • Where and How can I get the Black Lenovo Login Screen for Windows 7 for X120e?

    Hello, I just installed Windows 7 on a SSD on my X120e.  It is a fresh install and I really liked the Black Login Screen that my Lenovo X120e that came on the regular drive.  Is there a way to download this screen and make my login screen back to thi

  • Behaviour of ztables during upgrade

    Hi all I am trying to rationalise our ztables and would like to change the Delivery Class of some of our tables from 'W' to 'C' so that data can be transported through our landscape rather than manually entered on each system. I've read the SAP help

  • Can i Save Captured FLV files on different sever

    I am Capturing Video using Web Cam. And currently its saved on the same server. So, is it possible to save this on some CDN server, directly.?

  • PS  elements 5.2 Saving to jpeg

    I have PS Elements 5.2 and I am editing several pictures for eBay and they request a jpeg format.  My process is cropping a photo and adding text.  My problem (even though I try to following help istructions) is I can't save the rascals!  Can someone