Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  swing/jdialog dragable in specific area only.  (Read 1812 times)
0 Members and 1 Guest are viewing this topic.
Offline emzic

Senior Member





« Posted 2008-10-22 17:28:30 »

hello,

i have a swing interface, where i want a JDialog to be draggable only in a specific area. (pretty much exactly the area of the main window)

i tried it with a componentListener and setting the dialog back, whenever it is out of the specified bounds. unfortunately this leads to heavy flickering due to the jumping back of the JDialog.


(JInternalFrames are no option.)

thanks for any help!

www.embege.com - personal website
webstart blendinspect - OpenGL BlendingModes visualization.
Offline jezek2
« Reply #1 - Posted 2008-10-22 17:31:15 »

Why are JInternalFrames out of question?
Offline emzic

Senior Member





« Reply #2 - Posted 2008-10-22 17:47:23 »

Why are JInternalFrames out of question?

technical issues with lightweight-containers and jogl's GLCanvas that are not fixed until java7. Smiley

www.embege.com - personal website
webstart blendinspect - OpenGL BlendingModes visualization.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jezek2
« Reply #3 - Posted 2008-10-22 19:04:45 »

technical issues with lightweight-containers and jogl's GLCanvas that are not fixed until java7. Smiley

You can use heavyweight component (like Panel) inserted directly to JFrame (it will be on top of everything lightweight and also heavyweight if z order is set properly).
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 757
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2008-10-22 19:41:10 »

Does overriding setLocation/setBounds help?

Maybe the JVM catches the events from the OS, and passes them to the Component via those methods.

Probably not though...

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2008-10-22 21:44:55 »

Yeah your only hope is overriding something so that you can catch the desired positioning before the default stuff actually moves it. My best guess would be SetLocation like Riven said, although there might be something you can do in a window listener somewhere.

See my work:
OTC Software
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #6 - Posted 2008-10-22 23:13:32 »

Does overriding setLocation/setBounds help?

Maybe the JVM catches the events from the OS, and passes them to the Component via those methods.

Probably not though...

It's my understanding that it happens the other way around, when a heavy-weight Container is moved it is all handled within the native peer.
setLocation/setBounds are there to allow the Java app. to request the Containers native peer do its 'magic' to move the Component.

:edit: removed erroneous comment

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Mr_Light

Senior Member




shiny.


« Reply #7 - Posted 2008-10-22 23:41:11 »

ComponentPeer is pretty tucked away. windowlistener doesn't help.

If you can find a way it will be pretty hackery.

Just implement your own JInternalframe with whatever you are allowed to use. It's really not that complicated

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline jezek2
« Reply #8 - Posted 2008-10-23 00:25:13 »

You can use heavyweight component (like Panel) inserted directly to JFrame (it will be on top of everything lightweight and also heavyweight if z order is set properly).

I'm adding more concrete howto:

1. create Panel and store content of your dialog there (both AWT and Swing allowed here)
2. call setBounds for your Panel and add it to yourJFrame.getRootPane(), when added into root pane it's not affected by JFrame's layout manager, so you can set positon and size by setBounds
3. create your own JComponent for dialog frame (to which you add real dialog content), which you can use to move around and/or resize the dialog (the JInternalFrame can be probably tweaked to this, but I'm not sure how much work it is)

Don't forget to use reliable source for mouse location, eg. using location relative to parent is a bad choice, even if converted to absolute coordinates as the native events order is undefined and unsynchronized. Use MouseInfo class instead.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!