Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:22:38+00:00 2026-06-17T04:22:38+00:00

I am new in Swing. I have requirement to implement drag and drop using

  • 0

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 & 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

enter image description here

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 & Y Cooridnates and check the 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 > 0 && x > 0 && y < leftPanel.getHeight() && x < leftPanel.getWidth()) {
        leftPanel.add(new_lab(l, x, y));
                leftPanel.repaint();
        Component[] components1 = leftPanel.getComponents();
        Component component = null;
        for (int i = 0; i < components1.length; i++) {
          // System.out.println("components iii"+ components1[i]);
        component = components1[i];

            }

    }
}

});
}

Please tell me is there any missing here. What is best approches to achieve drag and drop functionality?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:22:39+00:00Added an answer on June 17, 2026 at 4:22 am

    This is not how drag and drop is accomplished in Java/Swing

    There are plenty of examples on SO…

    • Drag and Drop custom object from JList into JLabel
    • Java – How to drag and drop JPanel with its components
    • how to drag and drop files from a directory in java
    • Java – visually drag a swing element

    I’d also recommend that you checkout How to drag and drop with Java 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new to netbeans ide , i have a swing desktop application and
I tried to create a new Swing GUI desktop application template using NetBean 7.0
I have a field as: jFormattedTextFieldGrossWeight = new javax.swing.JFormattedTextField(); jFormattedTextFieldGrossWeight.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat(#,##0.00)))); I
I'm relatively new to java (specifically swing) and have recently been making some fairly
Let's say I have swing app and I am using mybatis: public class MyAppCView
I'm learning Swing and have composed an interface using a series of get methods
I have a JPanel that looks something like this: JPanel panel = new JPanel();
I am new to Swing. There is a silly question that I have. It
I have created a new project using the Create New Project Wizard, by choosing
I am new to Swing, UI and MVC I have created a code based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.