Looks like you are painting your root component into the buffered image in 
getRepresentation(). Try painting the TableViewHeader instead.

On Nov 11, 2011, at 11:05 AM, pan peter wrote:

> actually with following code i did manage to drag some thing while press on
> the table header, but it doesn't drag the table header, but somewhere else
> in the page, simply from (0, 0), not the actual table header location. See
> attached picture.
> 
> how to fix this?
> 
>        tableViewHeader = (TableViewHeader)namespace.get("tableViewHeader");
>        tableViewHeader.setDropTarget(new DropTarget(){
>            @Override
>            public DropAction dragEnter(Component arg0, Manifest arg1, int
> arg2, DropAction arg3)
>            {                return null;            }
> 
>            @Override
>            public void dragExit(Component arg0)            {            }
> 
>            @Override
>            public DropAction dragMove(Component arg0, Manifest arg1, int
> arg2,
>                    int arg3, int arg4, DropAction arg5)            {
>                return null;
>            }
> 
>            @Override
>            public DropAction drop(Component arg0, Manifest arg1, int arg2,
>                    int arg3, int arg4, DropAction arg5)
>            {
>                return null;
>            }
> 
>            @Override
>            public DropAction userDropActionChange(Component arg0,
>                    Manifest arg1, int arg2, int arg3, int arg4, DropAction
> arg5)
>            {
>                return null;
>            }});
> 
>        tableViewHeader.setDragSource(new DragSource(){
>            int selectedIndex;
>            @Override
>            public boolean beginDrag(Component arg0, int arg1, int arg2)
>            {
>                tableViewHeader = (TableViewHeader) arg0;
>                selectedIndex = tableViewHeader.getHeaderAt(arg1);
>                return true;
>            }
> 
>            @Override
>            public void endDrag(Component arg0, DropAction arg1){}
> 
>            @Override
>            public LocalManifest getContent(){
>                return null;
>            }
> 
>            @Override 
>            public Point getOffset() { 
>                    Point point = new Point(0, 0); 
>                    return point; 
>            } 
> 
> 
>            @Override
>            public Visual getRepresentation()
>            {
>                Picture picture = null; 
>                if (selectedIndex!=-1){ 
> 
>                    Bounds headerBounds = getHeaderBounds(selectedIndex);
>                    BufferedImage bImg = new
> BufferedImage(headerBounds.width, 
>                            headerBounds.height,
> BufferedImage.TYPE_INT_RGB); 
>                    Graphics2D graphics =  bImg.createGraphics();
>                    graphics.translate(headerBounds.x, headerBounds.y); 
>                    paint(graphics); 
>                    graphics.dispose(); 
>                    picture = new Picture(bImg); 
>                } 
> 
>                return picture; 
>            }
> 
>            private Bounds getHeaderBounds(int selectedIndex2)
>            {
>                return tableViewHeader.getHeaderBounds(selectedIndex2);
> 
>            }
> 
>            @Override
>            public int getSupportedDropActions()
>            {  return 0;        }
> 
>            @Override
>            public boolean isNative()
>            {
>                return false;
>            }});
> http://apache-pivot-users.399431.n3.nabble.com/file/n3500121/drag.jpg 
> 
> --
> View this message in context: 
> http://apache-pivot-users.399431.n3.nabble.com/how-to-use-drag-and-drop-swap-table-columns-tp3499066p3500121.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply via email to