Can anyone help in resizing the JLabel object
Hi,
can anyone help me in resizing the JLabel object after being dropped onto the DropContainer. I'm providing the code below
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.*;
import java.io.File;
import java.io.Serializable;
import java.awt.event.*;
import java.awt.Insets;
import java.awt.Dimension;
public class project2 extends JApplet implements Runnable{
private DragContainer dragcontainer;
private DropContainer dropcontainer;
private DefaultListModel listModel,listModel1;
public void start() {
Thread kicker = new Thread(this);
kicker.start();
public void run() {
project2 dndapplet = new project2();
dndapplet.init();
public void init() {
try {
getContentPane().setLayout(new BorderLayout());
listModel = new DefaultListModel();
dragcontainer = new DragContainer(listModel);
getContentPane().add(BorderLayout.WEST, new JScrollPane(dragcontainer));
listModel1=new DefaultListModel();
dropcontainer = new DropContainer(listModel1);
getContentPane().add(BorderLayout.CENTER,new JScrollPane(dropcontainer));
catch (Exception e) {
System.out.println("error");
fillUpList("images");
setSize(700, 300);
public static void main(String[] args) {
Frame f = new Frame("dndframe");
project2 dndapplet = new project2();
//Point pos=new Point();
f.add(dndapplet);
dndapplet.init();
dndapplet.start();
f.show();
private void fillUpList(String directory) {
File dir = new File(directory);
File[] files = dir.listFiles();
for (int i = 0; i < 11; i++) {
listModel.addElement(new ImageIcon(directory + "\\" + files.getName()));
class Cursor extends Object implements Serializable
public static final int SE_RESIZE_CURSOR=0;
int cursor;
public Cursor(int SE_RESIZE_CURSOR)
cursor=SE_RESIZE_CURSOR;
class ImageTransferable implements Transferable, Serializable
ImageIcon imageIcon;
public static final DataFlavor IMAGE_FLAVOR = DataFlavor.imageFlavor;
public DataFlavor[] getTransferDataFlavors()
return new DataFlavor[] {IMAGE_FLAVOR};
public ImageTransferable(ImageIcon imageIcon)
this.imageIcon = imageIcon;
public Object getTransferData(DataFlavor f) throws UnsupportedFlavorException
if (!isDataFlavorSupported(f))
throw new UnsupportedFlavorException(f);
return imageIcon;
public boolean isDataFlavorSupported(DataFlavor aFlavor)
return IMAGE_FLAVOR.equals(aFlavor);
class DragContainer extends JList implements DragGestureListener, DragSourceListener
private DragSource iDragSource = null;
public DragContainer(ListModel lm)
super(lm);
iDragSource = new DragSource();
iDragSource.createDefaultDragGestureRecognizer(this,DnDConstants.ACTION_COPY_OR_MOVE, this);
public void dragGestureRecognized(DragGestureEvent aEvt)
ImageIcon imageSelected = (ImageIcon) getSelectedValue();
ImageTransferable imsel = new ImageTransferable(imageSelected);
if (imageSelected != null)
System.out.println("startdrag...");
iDragSource.startDrag(aEvt, DragSource.DefaultCopyNoDrop, imsel, this);
else
System.out.println("Nothing Selected");
public void dropActionChanged(DropTargetDragEvent event)
public void dropActionChanged(DragSourceDragEvent event)
public void dragDropEnd(DragSourceDropEvent event)
public void dragEnter(DragSourceDragEvent event)
public void dragExit(DragSourceEvent event)
public void dragOver(DragSourceDragEvent event)
DragSourceContext context = event.getDragSourceContext();
context.setCursor(null);
context.setCursor(DragSource.DefaultCopyDrop);
class DropContainer extends JList implements DropTargetListener,MouseListener
private DropTarget iDropTarget = null;
private int acceptableActions = DnDConstants.ACTION_COPY_OR_MOVE;
JLabel imgLabel=null;
public int dropX;
public int dropY;
public int x;
public int y;
public DropContainer(ListModel lm1)
super(lm1);
iDropTarget = new DropTarget(this, this);
setBackground(Color.white);
public void drop(DropTargetDropEvent aEvt)
Point location=null;
ImageIcon icon=null;
Transferable transferable=null;
//int dropX=0;
//int dropY=0;
try
transferable = aEvt.getTransferable();
location=new Point();
if(transferable.isDataFlavorSupported(ImageTransferable.IMAGE_FLAVOR))
aEvt.acceptDrop(acceptableActions);
icon = (ImageIcon)
transferable.getTransferData(ImageTransferable.IMAGE_FLAVOR);
setLayout(null);
imgLabel=new JLabel();
imgLabel.setIcon(icon);
imgLabel.addMouseListener(this);
location=aEvt.getLocation();
dropX=location.x;
dropY=location.y;
imgLabel.setBounds(dropX,dropY,icon.getIconWidth(),icon.getIconHeight());
this.add(imgLabel);
SwingUtilities.updateComponentTreeUI(this.getRootPane());
aEvt.getDropTargetContext().dropComplete(true);
else
System.out.println("rejecting drop");
aEvt.rejectDrop();
aEvt.getDropTargetContext().dropComplete(false);
catch (Exception exc)
exc.printStackTrace();
aEvt.rejectDrop();
aEvt.getDropTargetContext().dropComplete(false);
finally
location=null;
transferable=null;
icon=null;
imgLabel=null;
public void mousePressed(MouseEvent e)
x=e.getX();
y=e.getY();
public void mouseReleased(MouseEvent e)
int temp1,temp2;
temp1=y;
temp2=x;
imgLabel.setSize(temp1,temp2);
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void dragEnter(DropTargetDragEvent event)
System.out.println("dragenter");
event.acceptDrag(acceptableActions);
public void dragExit(DropTargetEvent event)
System.out.println("dragexit");
public void dragOver(DropTargetDragEvent event)
System.out.println("dragover");
event.acceptDrag(acceptableActions);
public void dropActionChanged(DropTargetDragEvent event)
System.out.println("dropactionchanged");
event.acceptDrag(acceptableActions);
}//class DropContainer
Hi all,
I have two classes, say 1st and 2nd.
I have created an object of the second class in the first class and also i have invoked a method of the second class using it's object from the first class.
but when i compile the first class i'm getting an error that "cannot access the second class".
can anyone help me in fixing this problem
thanks in advance
murali
Similar Messages
-
I have an IPhone 4 and downloaded 12 songs from the Itunes store on my phone. I want to burn a CD but when I go into my ITunes on my desktop which is Windows XP there are only 7 listed not the 12 I bought. Can anyone help me find the others?????
Connect iPhone, then go to iTunes > File > Transfer purchases...
-
Can anyone help me change the DOB on my sons profile for his apple I'd so I can setup family sharing? I originally put both ids in my name. He is 19 do it keeps saying needs my permission but no instructions in how to get that done? His phone was stollen once last month need to get this done ASAP to prevent future headaches. Ty
You can not change the date of birth on the account. Apple makes that clear up front when the account is created.
The only way to "fix" this is going to be for him to create a new account with the correct information. Any apps purchased with the old one will need to be re-purchased with the new account. They can not be transferred. -
Can anyone help me? The iTunes update corrupted my program. I uninstalled, and then reinstalled iTunes; only to find an error message about iTunes Helper. After several fruitless, repeat attempts, I am at a loss. Please help…
Many thanks.
With the Error 2, let's try a standalone Apple Application Support install. It still might not install, but fingers crossed any error messages will give us a better idea of the underlying cause of the issue.
Download and save a copy of the iTunesSetup.exe (or iTunes64setup.exe) installer file to your hard drive:
http://www.apple.com/itunes/download/
Download and install the free trial version of WinRAR suitable for your PC (there's a 32-bit Windows version and a 64-bit Windows version):
http://www.rarlab.com/download.htm
Right-click the iTunesSetup.exe (or iTunes64Setup.exe), and select "Extract to iTunesSetup" (or "Extract to iTunes64Setup"). WinRAR will expand the contents of the file into a folder called "iTunesSetup" (or "iTunes64Setup").
Go into the folder and doubleclick the AppleApplicationSupport.msi to do a standalone AAS install.
Does it install properly for you?
If instead you get an error message during the install, let us know what it says. (Precise text, please.) -
Can anyone help me find the output option in Bridge CC?
Can anyone help me find the output option in Bridge CC?
http://helpx.adobe.com/bridge/kb/install-output-module-bridge-cc.html
-
Hey,I've got a problem on my iPad mini for a few days now?My iPad is in recovery mode at the moment and I Cannot restore my Ipad with iTunes...Can anyone help me with the solution?Each of your helps will be appreciate...Thanks for all the helps...
Follow step 1 to 6 closely to recover your iPad.
http://support.apple.com/kb/HT1808
Note: You may have to repeat the above a few times -
Can anyone help me display the calendar list using an iphone4 with iso 7.1.1? I have already tried tapping the magnifying glass and that doesn't work.
That icon allows for the calendar month to display with the appts for that month below. I want to see only the list of appointments without the month displaying. I use to be able to get that display but since the last update tapping the magnifiying glass doesn't work.
-
when I try to install this update I get the message an error has occured The operation couldn’t be completed. (NSURLErrorDomain error -3001.)(102) - can anyone help my get the update please?
There are problems with the servers. Download and install that update > http://swcdn.apple.com/content/downloads/53/02/041-8081/2jwp4wjrwygtm4lc608qy4h0 n4a9yyq37g/Safari6.0.2Mountain.pkg
-
Can anyone help me with the commands to import and restore backup from another administrative server
Dear all.
Can anyone help me with the commands to import and restore backup from another administrative serverI tried, even with code tags it looks the same since the 2500 character limit is exceeded.
Please post just the relevant parts inside tags as mentioned, and choose a descriptive subject line.
I'm locking this thread.
Thomas -
I can't find photos imported from my iPhone 4 with "Image Capture" to iPhoto anywhere... and they were deleted from the iPhone after import! Can anyone help me find the photos?
Do you know the date they were taken? Try search on that.
Regards
TD -
Can anyone help me find the free full semester labview course slides that were on the labview web site but recently disappeared. I would like to use them in my course.
The main page of the Academic section can be found here.
I think the material you are looking for is the courseware.
Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences. -
my ipod shuffle 4th gen bought today and the voice over works for naming playlist and battery percent but wont name song and artist can anyone help also is the voice over button meant to be soft when pushed ?
thanksThis document explains setting up and using VoiceOver.
http://support.apple.com/kb/ht4322
The overall settings for VoiceOver is on the shuffle's Summary screen in iTunes.
Artist name and song name - Press and release the VoiceOver button.
The playlist menu - Press and hold the VoiceOver button. -
Can anyone help me find the airplay function on my Macbook air (new)
Can anyone help me find the airplay function on my Macbook air (new)
Hi there,
I would recommend taking a look at the troubleshooting steps found in the article below.
Troubleshooting AirPlay and AirPlay Mirroring
http://support.apple.com/kb/TS4215
-Griff W. -
HT3986 Can anyone help me update the drivers on Bootcamp.
I use Bootcamp on my MacBook Pro (with Windows 7) for playing games and it has been working great. I recently purchased Battlefield 3 for PC and installed and it says I need to update the Nvidia drivers to a more recent patch, so I went to the website and downloaded it, but when I go to install them it says "This graphics driver could not find compatible graphics hardware". I have tried looking at a bunch of websites and can't find anything. Can anyone help me or tell me where to go to find help? It would be much appreciated!
Thanks, ZackYou can not change the date of birth on the account. Apple makes that clear up front when the account is created.
The only way to "fix" this is going to be for him to create a new account with the correct information. Any apps purchased with the old one will need to be re-purchased with the new account. They can not be transferred. -
The Border Of A JInternalFrame.. can anyone help me solve the bug?
Hi all,
I have many internal frames in my desktoppane and i want to set the border to color.blue of one of them at a time. I want to test if it is blue, if yes, then set the internal frame back to its original border, if it is not blue, then set to blue.. but there seems to be some error to do with metal borders..?? i am extremely confused.. can anyone help me.. sorry, but i am new to java
so i did..
in one of my classes...
JInternalFrame intFrame = new JInternalFrame;
inframe.setBorder(BorderFactory.createLineBorder(Color.blue));
then in main class i did..
public void SelectedInternalFrame(JInternalFrame intFrame)
this.selectedFrame = intFrame;
if(this.selectedFrame !=null)
Color c = ((LineBorder)this.selectedFrame.getBorder ()).getLineColor();
if (c == Color.blue)
///set back to the original border.. i dont know how to get it
thank u i advance
this.selectedFrame.setBorder(BorderFactory.createLineBorder(Color.blue,3));
}Hello Victoria, see IF in the next link the "Reset the connection settings in Yahoo Messenger" help you.
https://help.yahoo.com/kb/reset-connection-settings-resolve-sign-in-issues-sln1670.html?impressions=true
thank you
Maybe you are looking for
-
How can i import contacts from my regular sim to iphone 5 (nano sim)
how can i import contacts from my regular sim to iphone 5 (nano sim)
-
User id while creating a purchase order
Hello all, I would like to know whether there is any option to enter the user id or user name while creating a purchase order. If so could anyone post on how to do that. Thanks, Maxx
-
Compatability between Windows 8 and my HP Officejet J3680
I just got a new laptop with Windows 8. That is hard enough to get used to. Now my printer does not communicate with my laptop. I have downloaded drivers and updates. Changed portsand used HP Doctor whatever. Nothing seems to work. Help. This q
-
Hi guys, I'm new in LabWindows. I have a simple project, which has to parse a .txt file. Only some data inside the txt-File is interesting (the middle part, segment # 1-3 -> see example). The upper and lower part differs in size and is not important.
-
Why can't I sign into messages on OSX Mountain Lion?
I just upgraded to Mountain Lion on OSX and I cannot sign into Messages or FaceTime. I'm getting this message every time: "The server encountered an error processing registration. Please try again later." Any advice or anyone else experiencing this?