Dragging Object Between java windows inside java and other delphi panel - java

I have a Java AWT window inside of a Delphi panel (I know it's bad, but it's part of a large project that I can't change).
I want to drag an object from the Java AWT window to another Delphi panel (other than the one the AWT window is in).
Unfortunately, while dragging the object outside of the Java window, the focus stays on it (I guess the focus lasts as long as the mouse-dragging-event occurs).
Is there anyway to convert the mouse-dragging event of the Java window to the mouse-dragging event of the other Delphi panel while the mouse is being clicked?
Here is an image that shows how the window looks.

Related

Simulate mouse click/scroll/etc on swing without using Robot

I want to simulate basic input for a swing application. The whole thing runs headless and doesn't even have a JFrame. I just render all components from the JPanel using the draw() method on a Image (If you want to know why: The Image gets rendered on minecraft maps where users then should be able to interact). I want to execute click or scroll actions on the panel like it would come from regular user.
I know that I can simulate a Button click using doClick() but this doesn't work for components like checkboxes. I also tried using dispatchEvent() but that didn't fire the animations or on some components even threw a HeadlessException.

Recreate Windows Look-and-Feel border of JFrame or JDialog?

I need to recreate the translucent border of JFrame or JDialog that appears when setting the windows look and feel in swing.
I need it because Windows LaF does not let you access the title bar (on the border). In fact, I need to apply a MouseAdapter to the JDialog that gets notified when it is dragged/pressed/released. In windows laf, as you cannot get access to the bar component, you can only apply a ComponentListener which gives you notification only when moving (so you don't capture anything when the user has grabbed it but hasn't moved yet, or either when the user "releases" it).
Therefore, I decided to go with undecorated dialogs and apply the listeners to my custom bar. However I want the custom dialog looks exactly as in windows laf (it means I need to recreate the border).
I'm not very experienced in Graphics2D to override the paintBorder() method, so I'm asking for your help.
Has anyone ever faced this problem and has a tested solution?
As of the Java Platform, Standard Edition 6 (Java SE 6) Update 10 release, you can add translucent and shaped windows to your Swing applications.
This means that you can have your JFrame emulate a native window with the rounded corners and transparency.
In your case, your approach would be in the JFrame level instead of the border level because the border is painted on top of the JFrame (or JDialog, for that matter). Therefore, if the JFrame is not already rounded, for instance, the paintBorder() method will still be painting on top of a rectangular area of the screen.
Check this tutorial from Oracle covering shaped and translucent JFrame.

Java Swing - user alerts

I am trying to build a user alert mechanism by bringing up the window to the front and then flashing the icon on the screen for the user. I have two questions with regards to this approach:
How can you find the current window you are at in Java and then de-minimize it and bring to front?
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
Thanks a lot for any replies.
How can you find the current window you are at in Java and then de-minimize it and bring to front
Window[] allWindows = Window.getWindows();
returns arrays of all Top-Level Containers from current JVM e.g. J/Frame, J/Dialog(JOptionPane), J/Window,
you can to test for (example) if (allWindows[i] instanceof JFrame) {
then WindowState returned WindowEvent
by bringing up the window to the front and then flashing the icon on the screen for the user
use undecodated JDialog (works toFront, toBack) with
create only once time
setDefaultCloseOperations(HIDE_ON_CLOSE)
use Swing Timer for hide JDialog
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
have look at Java Translucent Window, put there Icon to the JLabel (or to the JButton)
use Swing Timer for flashing by hiding Icon or swithing bewtween two or more Icons (three or four is good)
I think the simplest way to get the window ancestor is :
SwingUtilities.getWindowAncestor(yourComponent);

PopupMenu freezing parent frame

I'm using a AWT PopupMenu on a frame that constantly repaints (it's a game), but whenever the PopupMenu shows, the parent frame freezes. Is there a way to disable this?
I assume the rest of the application is in made in Swing and you are using the AWT popmenu in combination with Swing components.
I've had my fair share of AWT PopMenu problems. Do you need to show the Popmenu outside the bounds of your application ? If you only need to be able to show it inside your application (JFrame) you are probably beter off with just putting a JComponent on top of all your other panels (with a JLayredPane) and draw your own pop menu there.
Even easier is to use JLayer in Java 7 for the same effect (or JXLayer if your not on Java 7 but on Java 5 or 6).
The above method is also way more powerful then the AWT popmenu because you control the drawing. So for example making it translucent or giving it round edges becomes a breeze.

Java (Swing) - Drag two windows at once

How can I have one window move with another? i.e., I'd like a JDialog to follow a JFrame when the JFrame is being dragged. If the JFrame moves by (+5, +20), the JDialog needs to move the same.
I've tried using ComponentListeners, but I only receive drag events in chunks which causes the JDialog window to be jumpy while dragging the main JFrame. I've tried using MouseListeners, but I can't figure out how to detect events on the actual frame of the JFrame.
AFAIK here is no move multiple windows in AWT. To get the moves to be called at a similar time, I guess you want the JFrame decorations to be PL&F rendered. Put in a PL&F-specific hack to do the moves yourself, moving both windows at almost the same time. You may still have a problem with exposing bits of windows only to cover them up causing some performance degradation.
Try using the ComponentListener.componentMoved event instead of monitoring drag events on the JFrame.
The component listener method works perfectly.
I did something like this:
Point p = this.getLocation();
p.x += this.getWidth() + 10;
this.getOwner().setLocation(p);
Where the '10' is the space between the current window(a JDialog) and its owner which is to its right.

Categories