Note that there are some explanatory texts on larger screens.

plurals
  1. PODrag and Drop between two panels using swing?
    primarykey
    data
    text
    <p>I am new in Swing. I have requirement to implement drag and drop using swing. In current frame contains different panels i.e.,Center Panel &amp; LeftPanel have sub panels i.e., Controls Panel,Properties Panel.I trying to drag and drop the labels/jbuttons/Images from Control Panel into Center Panel.These panels are used BorderLayout</p> <p><img src="https://i.stack.imgur.com/G8lTK.jpg" alt="enter image description here"></p> <p>I tried drag and drop with Mouse Event.I put mouse listner on Control Panel. When I dropping the label/image into center panel.It reads -X &amp; Y Cooridnates and check the code</p> <pre><code>private void mak_lis(final SLabel l) { l.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent m) { System.out.println("mak_lis Mouse mousePressed"); setCursor(yd); // l.setBorder(new MatteBorder(1,1,1,1,Color.black)); } public void mouseReleased(MouseEvent m) { l.setBorder(null); setCursor(dc); System.out.println("mak_lis Mouse mouseReleased"); int x = -(m.getX() + l.getX() - leftPanel.getX()); int y = m.getY() + l.getY() + leftPanel.getY(); System.out.println("mak_lis Mouse mouseReleased" + "x" + x+ "y" + y); if (y &gt; 0 &amp;&amp; x &gt; 0 &amp;&amp; y &lt; leftPanel.getHeight() &amp;&amp; x &lt; leftPanel.getWidth()) { leftPanel.add(new_lab(l, x, y)); leftPanel.repaint(); Component[] components1 = leftPanel.getComponents(); Component component = null; for (int i = 0; i &lt; components1.length; i++) { // System.out.println("components iii"+ components1[i]); component = components1[i]; } } } }); } </code></pre> <p>Please tell me is there any missing here. What is best approches to achieve drag and drop functionality?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload