Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Swing / AWT / SWT
Drag n Drop
sun par
Ranch Hand
Posts: 257
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I need to learn Drap n Drop capabilities of Swing. Can someone suggest some material for it??
Thanks
Sunita<br />SCJP 1.4
Dirk Schreckmann
Sheriff
Posts: 7023
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'd suggest taking a look at
The Drag and Drop Trail of Sun's
Java
Tutorial, taking a look at
The Drag and Drop section of the J2SE Documentation
, and trying a quick search on this forum. (The search page link is at the top-right of this page.)
Good luck.
[ April 03, 2003: Message edited by: Dirk Schreckmann ]
[
How To Ask Good Questions
] [
JavaRanch FAQ Wiki
] [
JavaRanch Radio
]
Manish Hatwalne
Ranch Hand
Posts: 2596
I like...
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Also have a look at
this tip
from the latest Tech Tip by Sun.
- Manish
Yoo-Jin Lee
Ranch Hand
Posts: 119
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
Here's some code for drag n drop and cut and paste:
package test.swing; import uk.co.aps.swing.SwingWorker; import java.awt.*; import java.awt.datatransfer.*; import java.awt.dnd.*; import java.awt.event.*; import javax.swing.*; public class Progress extends JPanel { private BorderLayout borderLayout1 = new BorderLayout(); private static JProgressBar bar = new JProgressBar(); private JButton btn = new JButton(); private final void pasteIt() { final SwingWorker worker = new SwingWorker() { public Object construct() { try { int total = 100; bar.setMaximum(total); bar.setMinimum(0); for (int i = 0; i < total; i++) { try { Thread.sleep(100); } catch (InterruptedException ex) { } bar.setValue(i); } } catch (Exception e) { } return null; } public void finished() { } }; worker.start(); } public Progress() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { this.setLayout(borderLayout1); this.setDoubleBuffered(false); bar.setDoubleBuffered(false); btn.setDoubleBuffered(false); btn.setText("import"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { pasteIt(); } }); this.add(bar, BorderLayout.SOUTH); this.add(btn, BorderLayout.CENTER); } public static void main(String[] args) { Progress dndTest = new Progress(); javax.swing.JFrame frame = new javax.swing.JFrame(); frame.getContentPane().add(dndTest, java.awt.BorderLayout.CENTER); frame.pack(); frame.setSize(500, 100); frame.setLocation(300, 600); frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // uncomment to see it work correctly // dndTest.pasteIt(); } } package test.swing; import javax.swing.SwingUtilities; /** * This is the 3rd version of SwingWorker (also known as * SwingWorker 3), an abstract class that you subclass to * perform GUI-related work in a dedicated thread. For * instructions on using this class, see: * * <http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html> * * Note that the API changed slightly in the 3rd version: * You must now invoke start() on the SwingWorker after * creating it. */ public abstract class SwingWorker { private Object value; // see getValue(), setValue() private Thread thread; /** * Class to maintain reference to current worker thread * under separate synchronization control. */ private static class ThreadVar { private Thread thread; ThreadVar(Thread t) { thread = t; } synchronized Thread get() { return thread; } synchronized void clear() { thread = null; } } private ThreadVar threadVar; /** * Get the value produced by the worker thread, or null if it * hasn't been constructed yet. */ protected synchronized Object getValue() { return value; } /** * Set the value produced by worker thread */ private synchronized void setValue(Object x) { value = x; } /** * Compute the value to be returned by the <code>get</code> method. */ public abstract Object construct(); /** * Called on the event dispatching thread (not on the worker thread) * after the <code>construct</code> method has returned. */ public void finished() { } /** * A new method that interrupts the worker thread. Call this method * to force the worker to stop what it's doing. */ public void interrupt() { Thread t = threadVar.get(); if (t != null) { t.interrupt(); } threadVar.clear(); } /** * Return the value created by the <code>construct</code> method. * Returns null if either the constructing thread or the current * thread was interrupted before a value was produced. * * @return the value created by the <code>construct</code> method */ public Object get() { while (true) { Thread t = threadVar.get(); if (t == null) { return getValue(); } try { t.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // propagate return null; } } } /** * Start a thread that will call the <code>construct</code> method * and then exit. */ public SwingWorker() { final Runnable doFinished = new Runnable() { public void run() { finished(); } }; Runnable doConstruct = new Runnable() { public void run() { try { setValue(construct()); } finally { threadVar.clear(); } SwingUtilities.invokeLater(doFinished); } }; Thread t = new Thread(doConstruct); threadVar = new ThreadVar(t); } /** * Start the worker thread. */ public void start() { Thread t = threadVar.get(); if (t != null) { t.start(); } } }
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
SCMAD Details
DRAG N DROP QUESTIONS
dnd using control key..urgent
OCE, JEE 6 JSP and Servlets Developer
Exam Question
More...