Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1340 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  
 
 

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

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

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

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

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

nelsongames (157 views)
2018-04-24 18:14:32

ivj94 (899 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (812 views)
2018-03-24 14:43:53

Solater (175 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!