• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Sample code to drag drop buttons in Applet

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Thanks!
Asif
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
item4.setText((String)event.data);
System.out.println("here to refresh the screen");
shell.redraw();

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: " +
((TreeItem)e.item).getText());
if(count==0)
{
count=1;
System.out.println("here to refresh the on mouse click");
shell.redraw();

display.readAndDispatch();
displaytext = new Text(shell, SWT.BORDER);
displaytext.setText(((TreeItem)e.item).getText());
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(displaytext.getText());
// ((TreeItem)e.item).setText("abcd");
System.out.println("go this ayararer");
displaytext.dispose();
okButton.dispose();
count=0;
// display.readAndDispatch();
okButton.dispose();

}
};

okButton.addListener(SWT.Selection, listener);

}

}
});




} }
);


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

if (!display.readAndDispatch())
{
display.sleep();

}
}
display.dispose();




}


}



Thanks in advance!

 
The only thing that kept the leeches off of me was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic