• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sample code to drag drop buttons in Applet  RSS feed

Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Please help me to create an single applet with two partition say panel 1 and panel 2 and some buttons in panel one should be able to drag drop to panel two.

I am not getting code for this anywhere in net, please help me to develop this.

Posts: 11445
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Asif,
We do not just hand out ready made code here at the Ranch.
More details can be found here
Show us what you have got so far, and we will help you fix it.
Asif Usman
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Maneesh,

Sorry for that, i got some code. Can you help me to resolve the position issue which i am phasing now.

initially i get a window with two division, in which i drag text from one division to another. I am using SWT package,

in the second window when i click any dropped text, it should automatically open third division to edit that selected text and a button to finish the update task.

Right now i am able to do the all the task but when i select a item to edit, the screen is not updating, i have to re size the screen to see the button and editable text.

Can you help me to resolve this issue.

here is the code

* To change this template, choose Tools | Templates
* and open the template in the editor.

package test;

import javax.swing.JTextField;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TreeAdapter;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class doitforme

public int count=0;
TreeItem item4;
Shell shell;
Display display ;
Text displaytext;
public doitforme()

// item4=new TreeItem();

public void getthatworkdone()

display = new Display();
shell = new Shell(display);

shell.setLayout(new FillLayout());
shell.setText("Drag and Drop");
final Tree tree = new Tree(shell, SWT.BORDER);
TreeItem item1 = new TreeItem(tree, SWT.NONE);

item1.setText("Hello 1");
TreeItem item2 = new TreeItem(tree, SWT.NONE);
item2.setText("Hello 2");
TreeItem item3 = new TreeItem(tree, SWT.NONE);
item3.setText("Hello 3");
TreeItem item5 = new TreeItem(tree, SWT.NONE);
item5.setText("Hello 4");

DragSource ds = new DragSource(tree, DND.DROP_MOVE);
ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
ds.addDragListener(new DragSourceAdapter() {
public void dragSetData(DragSourceEvent event) {
event.data = tree.getSelection()[0].getText();

// final Text text = new Text(shell, SWT.BORDER);

final Tree tree1 = new Tree(shell, SWT.BORDER);

DropTarget dt = new DropTarget(tree1, DND.DROP_MOVE);

dt.setTransfer(new Transfer[] { TextTransfer.getInstance() });
dt.addDropListener(new DropTargetAdapter(){

public void drop(DropTargetEvent event) {
item4 = new TreeItem(tree1, SWT.NONE);
System.out.println("here to refresh the screen");

System.out.println("ok droped one item");
tree1.addTreeListener(new TreeListener() {
public void treeExpanded(TreeEvent e) {
System.out.println("expanded: " + ((TreeItem)e.item).getText()); }

public void treeCollapsed(TreeEvent e) {
System.out.println("collapsed: " + ((TreeItem)e.item).getText());


tree1.addSelectionListener(new SelectionAdapter(){
public void widgetSelected( final SelectionEvent e) {
System.out.println("selected: " +
System.out.println("here to refresh the on mouse click");

displaytext = new Text(shell, SWT.BORDER);
final Text abcd = displaytext;
final Button okButton = new Button(shell, SWT.ABORT);
// Button newone =new Button(shell.getParent(),SWT.CLIP_SIBLINGS);
okButton.setSize(100, 100);
Listener listener = new Listener() {
public void handleEvent(Event event) {

// ((TreeItem)e.item).setText("abcd");
System.out.println("go this ayararer");
// display.readAndDispatch();


okButton.addListener(SWT.Selection, listener);



} }

shell.setSize(1000, 500);
while (!shell.isDisposed())

if (!display.readAndDispatch())




Thanks in advance!

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!