🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #752

dropping JLabel onto JPanel

#752
From: Alan Shiers
Date: Wed, 08 Dec 2004 16:41
42 lines
2749 bytes
Hi there,

I'm working on a Drag 'n Drop project. I simply want to drag items from a
class that extends JList to another class that extends JPanel. In my
project, the class that extends JList is named: MutableList.  The class that
extends JPanel is named:
TargetPanel.  It is supposed to be a simple one-way COPY procedure. I have
it set up so that MutableList has single selection and displays objects that
represent various types of items: radiobutton, checkbox, listbox, textbox,
etc.  Each of these are rendered using a class that implements
ListCellRenderer; which extends JLabel and renders an image of the various
items into MutableList.

This much is working so far. All my code compiles fine.  The problem I am
facing now is at runtime during the actual drop procedure.  I have no
problem selecting an item from the MutableList and begin dragging it over to
the TargetPanel.  The TargetPanel class has a method called
addElement(Component c).  Here is what it looks like:

public void addElement(Component c)
{
    add(c);
    Component[] comp = this.getComponents();
    if(comp[0] instanceof MyComponent)
      System.out.println("comp is instanceof MyComponent");
    repaint();
}

Note the MyComponent object mentioned in the method. I test to ensure that
TargetPanel did indeed receive the drop with the instanceof operator. When I
run this code, I do indeed get the println statement executed, so I know its
there. The MyComponent object extends JLabel and is a new instance
representing a copy of the original item in MutableList.
Now, note that I then call repaint().  This is an attempt in making this
instance of MyComponent visibly appear in TargetPanel. Well, surprise,
surprise!  It doesn't!

What am I doing wrong?  How do I make MyComponent appear in TargetPanel?

Please advise,

Alan
Technical Details
Message-ID: <41b72f96@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,e3d7c8a55e0aeecb,start
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Alan Shiers" <ashiers@hfx.eastlink.ca>
Newsgroups: borland.public.jbuilder.java.swing
Subject: dropping JLabel onto JPanel
Date: Wed, 8 Dec 2004 12:41:32 -0400
Lines: 44
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 24.222.101.2
Message-ID: <41b72f96@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102524310 24.222.101.2 (8 Dec 2004 08:45:10 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail