Hi Brendan, My guess would be that you are putting the column back in the same place that it was. I would check indexes and things in the end drop method. Without analyzing the code in detail that would be the first thing I would check. If that is not the case (the indexes are all what you expect) then I would make sure that all the proper methods are being called at the right time. After that, you will have to do some old-fashioned debugging on it. Do you have a Java debugger setup (like Eclipse or NetBeans or jswat)?
On first examination it seems like most everything is correct, so it's probably something pretty simple. HTH, ~Roger Whitcomb Sent from my iPhone On Dec 6, 2012, at 4:44 AM, Brendan cheng <[email protected]> wrote: > Hi, > > > > I tried to implement a drag and drop function on column of table view header. > I followed an example of Demo and coded as followed but nothing happened. > Could you give me some advice on my code? > > > > Brendan > > > > Here is: > > primaryHeader.setDragSource(new DragSource() { > > > > private LocalManifest content = null; > > > > @Override > > public boolean beginDrag(Component component, int x, > int y) { > > int columnIndex = > primaryHeader.getTableView().getColumnAt(x); > > Column column = primaryHeader.getTableView() > > .getColumns().get(columnIndex); > > if (column != null) { > > content = new LocalManifest(); > > dragDropKey = column.getName(); > > content.putValue(dragDropKey, column); > > } > > > > return (content != null); > > } > > > > @Override > > public void endDrag(Component component, DropAction > dropAction) { > > content = null; > > > > } > > > > @Override > > public boolean isNative() { > > return true; > > } > > > > @Override > > public LocalManifest getContent() { > > return content; > > } > > > > @Override > > public Visual getRepresentation() { > > // TODO Auto-generated method stub > > return null; > > } > > > > @Override > > public Point getOffset() { > > // TODO Auto-generated method stub > > return null; > > } > > > > @Override > > public int getSupportedDropActions() { > > return DropAction.COPY.getMask(); > > } > > }); > > > > primaryHeader.setDropTarget(new DropTarget() { > > @Override > > public DropAction dragEnter(Component component, > > Manifest dragContent, int > supportedDropActions, > > DropAction userDropAction) { > > DropAction dropAction = null; > > > > if (dragContent.containsValue(dragDropKey) > > && > DropAction.COPY.isSelected(supportedDropActions)) { > > dropAction = DropAction.COPY; > > } > > > > return dropAction; > > } > > > > @Override > > public void dragExit(Component component) { > > // empty block > > } > > > > @Override > > public DropAction dragMove(Component component, > > Manifest dragContent, int > supportedDropActions, int x, > > int y, DropAction userDropAction) { > > return (dragContent.containsValue(dragDropKey) > ? DropAction.COPY : null); > > } > > > > @Override > > public DropAction userDropActionChange(Component > component, > > Manifest dragContent, int > supportedDropActions, int x, > > int y, DropAction userDropAction) { > > return (dragContent.containsValue(dragDropKey) > ? DropAction.COPY : null); > > } > > > > @Override > > public DropAction drop(Component component, Manifest > dragContent, > > int supportedDropActions, int x, int y, > > DropAction userDropAction) { > > DropAction dropAction = null; > > int columnIndex = > primaryHeader.getTableView().getColumnAt(x); > > if (dragContent.containsValue(dragDropKey)) { > > try { > > primaryHeader > > .getTableView() > > > .getColumnSource() > > .getColumns() > > > .remove((Column) dragContent > > > .getValue(dragDropKey)); > > primaryHeader > > .getTableView() > > > .getColumnSource() > > .getColumns() > > > .insert((Column) dragContent > > > .getValue(dragDropKey), columnIndex); > > dropAction = DropAction.COPY; > > } catch (IOException exception) { > > System.err.println(exception); > > } > > } > > > > dragExit(component); > > > > return dropAction; > > } > > }); > >
