This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes How to drag an applet using Alt + Leftclick to an new window and not the default JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "How to drag an applet using Alt + Leftclick to an new window and not the default JFrame" Watch "How to drag an applet using Alt + Leftclick to an new window and not the default JFrame" New topic
Author

How to drag an applet using Alt + Leftclick to an new window and not the default JFrame

Jacques Gertenbach
Greenhorn

Joined: Jun 17, 2009
Posts: 4
Please help. I developed a PDF and Tiff image viewer as an applet.
Its working fine, but I have the following problem.

Applests cant resize, so now I'm trying to drag the applet of the page by using the new Alt + Leftclick,
The new draggable functionality from Java 1.6.10.
It works fine, but I want it to become a windowed frame so that it can be resized.

Any body please!!!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Hi Jacques,
Welcome to the Ranch.

Can you please elaborate on what you mean by windowed frame?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jacques Gertenbach
Greenhorn

Joined: Jun 17, 2009
Posts: 4
With the new Java 1.6.10 release you are nou able to drag and drop you applets out of a web page to be stand alone applications on the desktop, using Alt + Left click.
It works fine, but once you have done so, you cannot resize the applet. This is due to the fact that the applets parent containter is a Frame without any features. It only gives you a little black x at the top right to close the applet which anchers it back to your page.
I have mangange to detach the applet by using the following code, but I would like to keep the Alt + Left click functionality and force the applet into a visable framed window that can be resized.
Meaning, I would like to be able to minipulate the parent container that is created by the Draggable functionality now available in 1.6.10.

Thanks


public void putInFrame()
{
AttachDetachButton.setText("Attach");
bStandalone = true;
dimOrigSize = new Dimension(getSize());
myParent = getParent();
myFrame = new DetachedJFrame(this,"Image Viewer");
Dimension siz = new Dimension(dimOrigSize);
myFrame.setSize(siz);
myFrame.add("Center",this);
myFrame.setVisible(true);
}

public void removeFromFrame()
{
AttachDetachButton.setText("Detach");
bStandalone = false;
myFrame.remove(imageViewer);
myFrame.dispose();
myFrame = null;
myParent.add("Center",imageViewer);
resize(dimOrigSize);
myParent.setVisible(true);
}



class DetachedJFrame extends JFrame
{
private ImageViewer iv;

public DetachedJFrame(ImageViewer imageViewer,String strName)
{
super(strName);
iv = imageViewer;
}

@Override
public void processEvent(AWTEvent evt)
{
if (evt.getID() == WindowEvent.WINDOW_CLOSING) {
iv.removeFromFrame();
return;
}
processWindowEvent((WindowEvent)evt);
}

}
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Shouldn't you be defining the J/Frame in the appletDragStarted()?
Jacques Gertenbach
Greenhorn

Joined: Jun 17, 2009
Posts: 4
I tied that, but it creats an artifact the size of the original applet somewhere on the screen. So something not releasing properly.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Somewhere on the screen would be where the user dropped it!
Have you set your JFrame to be resizable? If yes, can you post your appletDragStarted() code?
Jacques Gertenbach
Greenhorn

Joined: Jun 17, 2009
Posts: 4
I unfortunalty do not have the code any more. After implementing the new code I did a cleanup.
Yes the JFrame in the dragstart event was sizeable.

The frame that java is creating in the draggable functionality is killing or interfeering with JFrame I am implementing.

I will see if I can recreate the code for you. Dont have too much time on my hands at the moment
 
jQuery in Action, 2nd edition
 
subject: How to drag an applet using Alt + Leftclick to an new window and not the default JFrame
 
Similar Threads
Mouse Drag Event
how to get menupopup on mouse leftclick
Applet and Servlet connection
press leftclick and a menu appers
want to disable ALT+TAB key using java