Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (784)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (859)
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 and OpenGL  (Read 1464 times)
0 Members and 1 Guest are viewing this topic.
Offline DaveLloyd

Junior Devvie

Making things happen fast with Java!

« Posted 2005-12-01 15:58:39 »

I've been using Swing as my widget toolkit on OpenGL with some success but have run into a few deep problems with the way Swing relies on AWT to dispatch events and was hoping someone here might be able to help.

I'm using Agile2D to provide me with a Graphics2D object that Swing components can use to directly draw into the OpenGL frame. This is working pretty well perfectly on the visual side.

My GLCanvas lives in a panel that also contains a custom JRootPane that holds the 2d components sitting on the 3d scene (the hud). The GLCanvas receives all mouse and keyboard events and forwards them to the JRootPane which dispatches them to the components beneath (with some code v similar to that used by JInternalFrame - find the deepest component under the mouse that has a listener and retarget the event to that component). The JRootPane also kicks off the painting of the components with the Agile2D Graphics object. There are a few other wrinkles such as a custom RepaintManager that blocks repaints to such components (because they are drawn every frame anyway).

However the problems come with two special cases:

(1) The drop down menu with a JComboBox only receives keyboard events. It seems that a mouse click on an item in the menu (actually a JList with the basic UI) gets intercepted by the focus manager and (presumably) since the target is the GLCanvas as far as the focus manager is concerned, it sends a focus lost event that hides the JList before the mouse click event reaches it. I'm not very familiar with how the focus manager works - can anyone suggest a sensible way to correct this behaviour?

(2) Modal dialogs - particularly those created by JOptionPane - do something very hairy with the event queue involving a call to startLWModal (backdoor via reflection - yuck!) with the result that key events reach them but mouse events do not - perhaps because it thinks the GLCanvas and the JRootPane have different HW containers? I am really at a loss how to resolve this one.

I guess I can find alternative workaround to these particular problems - the focus manager is not so relevant in a game UI, so a custom ComboBoxUI might be one solution. Similarly I can avoid modal dialogs. But it would be nice to have all of Swing available not some irregular subset.

Incidentally when it comes to the next major revision of Swing, might I suggest cutting it completely loose from the AWT Component hierarchy and building it as an independent layer with clear event input and drawing entry points. It would certainly make it more adapatable to uses such as game UIs.

Offline Linuxhippy

Senior Devvie

Medals: 1

Java games rock!

« Reply #1 - Posted 2005-12-01 18:31:30 »

Since some recent Mustang builds you have the possibility to mix&match Swing and JOGL so maybe this is an already working solution for what you're searching. Even clipping works perfectly.

lg Clemens
Pages: [1]
  ignore  |  Print  

hadezbladez (1655 views)
2018-11-16 13:46:03

hadezbladez (667 views)
2018-11-16 13:41:33

hadezbladez (1646 views)
2018-11-16 13:35:35

hadezbladez (351 views)
2018-11-16 13:32:03

EgonOlsen (2704 views)
2018-06-10 19:43:48

EgonOlsen (2971 views)
2018-06-10 19:43:44

EgonOlsen (1657 views)
2018-06-10 19:43:20

DesertCoockie (2373 views)
2018-05-13 18:23:11

nelsongames (2286 views)
2018-04-24 18:15:36

nelsongames (2977 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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‑
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!