Skip to main content



      Home
Home » Eclipse Projects » NatTable » Nattable column and row resize behaviour(Would like change to be dynamic whilst user is moving mouse)
Nattable column and row resize behaviour [message #1707395] Fri, 04 September 2015 09:13 Go to next message
Eclipse UserFriend
Hi everyone

I am developing an application that has a number of small Nattables to display various information.

The user can manually alter the column widths & row heights using mouse drags on the headers. Great, but for visual aesthetics I would prefer the column widths & row heights to change dynamically whilst the user is moving the mouse, instead of jumping to the new size when the user releases the mouse button.

Any hints or tips how this can be achieved?

Willing to do a bit of coding to achieve but looking around the Javadoc and the source code, not sure how to make this happen!

Understand the current/default behaviour was for performance reasons, but my tables are simple enough and the machines powerful enough that I think this won't be a problem.

Any help gratefully received
Many thanks
Richard
Re: Nattable column and row resize behaviour [message #1707456 is a reply to message #1707395] Fri, 04 September 2015 15:19 Go to previous messageGo to next message
Eclipse UserFriend
Have a look at the ColumnReorderDragMode. If you create and register a custom implementation that performs the resize actions on mouse move it might work the way you want.
Re: Nattable column and row resize behaviour [message #1707723 is a reply to message #1707456] Tue, 08 September 2015 15:04 Go to previous message
Eclipse UserFriend
Many thanks Dirk, just the hint I needed. Smile

Now all successfully implemented and working very well.

For those who might want to do the same, he is what I did:
(1) When creating the ColumnHeaderLayer added custom config, remembering to say false to useDefaultConfiguration.
(2) In custom config add custom ColumnResizeDragMode, in my case called XColumnResizeDragMode
              uiBindingRegistry.registerFirstMouseDragMode( new ColumnResizeEventMatcher( SWT.NONE,
                  GridRegion.COLUMN_HEADER, 1 ), new XColumnResizeDragMode() );

(3) And here is my XColumnResizeDragMode
public class XColumnResizeDragMode implements IDragMode
{
  private int              m_column;
  private int              m_originalWidth;
  private int              m_originalX;

  private static final int MIN_COLUMN_WIDTH = 25;

  /****************************************** mouseDown ******************************************/
  @Override
  public void mouseDown( NatTable nattable, MouseEvent event )
  {
    // determine which column is being resized
    nattable.forceFocus();
    m_column = CellEdgeDetectUtil.getColumnPositionToResize( nattable, new Point( event.x, event.y ) );

    if ( m_column >= 0 )
    {
      m_originalWidth = nattable.getColumnWidthByPosition( m_column );
      m_originalX = event.x;
    }
  }

  /****************************************** mouseMove ******************************************/
  @Override
  public void mouseMove( NatTable nattable, MouseEvent event )
  {
    // determine new width
    int width = m_originalWidth + event.x - m_originalX;

    // don't allow width to go below minimum
    if ( width < MIN_COLUMN_WIDTH )
      width = MIN_COLUMN_WIDTH;

    // update table column width and trigger redraw
    nattable.doCommand( new ColumnResizeCommand( nattable, m_column, width ) );
    nattable.redraw();
  }

  /******************************************* mouseUp *******************************************/
  @Override
  public void mouseUp( NatTable nattable, MouseEvent event )
  {
    // nothing to do
  }

}
Previous Topic:Tree Example With the Filter Problem
Next Topic:CellEditor isn't exactely in the appropriate nattable Cell after commiting the first edition
Goto Forum:
  


Current Time: Sun Jun 22 11:57:01 EDT 2025

Powered by FUDForum. Page generated in 0.03742 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top