Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  JOGL + AWT or Swing  (Read 2137 times)
0 Members and 1 Guest are viewing this topic.
Offline shaddam_IV

Junior Devvie




Java makes me happy the way C# doesn't!


« Posted 2003-12-05 05:08:15 »

Have any of you had any luck inserting a GLCanvas as a pane in a Swing app?  The only time I can get JOGL to work properly is when it is the only image and is taking up all of the real estate on the frame.

I would like the ability to have a portion of the Frame available for things like buttons, sliders, or other simple controls.  This could work by having multiple JPanels, with the canvas covering one panel, but I can't get this to work.  Have any of you done this successfully?

Thanks,
Jeeky

There are 10 kinds of people in the world.  Those that understand binary and those that don't.
Offline AvengerDr

Senior Newbie




Java games rock!


« Reply #1 - Posted 2003-12-05 05:54:23 »

I am developing a JOGL app with some swing components on it. Everything works fine! I used the border layout manager and put various Jpanels in the frame with the GLCanvas in a Jpanel in the center area.

What is the problem that you are experiencing?
Offline shaddam_IV

Junior Devvie




Java makes me happy the way C# doesn't!


« Reply #2 - Posted 2003-12-05 13:13:48 »

The GLCanvas doesn't appear to be present on the JPanel, or at least it isn't getting sized right.  I can call setSize(x, y) on the GLCanvas in the constructor, and then the GLCanvas is present, but not sized right.

I guess the problem is that I am unable to get the canvas to size properly when the parent panel is resized.  It seems like the GLEventListener isn't getting registered properly with a JPanel of something.

Do you attach the canvas to your panel by using JPanel.add(myGLCanvas) or do you do something else?  Is there any special code you need to implement to get the sizing to work?

There are 10 kinds of people in the world.  Those that understand binary and those that don't.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pepijnve

Junior Devvie




Java games rock!


« Reply #3 - Posted 2003-12-05 13:55:06 »

I add a GLCanvas to a JPanel using a BorderLayout. The GLCanvas resizes as it should.
1  
2  
3  
GLCanvas c;
JPanel p = new JPanel(new BorderLayout());
p.add(c, BorderLayout.CENTER);
Offline shaddam_IV

Junior Devvie




Java makes me happy the way C# doesn't!


« Reply #4 - Posted 2003-12-06 02:51:43 »

Thanks pep, that worked like a charm.  It appears that the default flow layout has issues.

There are 10 kinds of people in the world.  Those that understand binary and those that don't.
Offline aldacron

Senior Devvie


Medals: 9
Exp: 16 years


Java games rock!


« Reply #5 - Posted 2003-12-06 07:17:28 »

No it doesn't have issues, it just works differently than BorderLayout. You really have to understand the default behavior of each layout and each component to get the most out of using them.

Two Component methods come into play when added to a Container - getPreferredSize() and getMinimumSize(). Some layout managers may or make not make use fo these. For example, a FlowLayout is gauranteed to respect both the preferred width and height, while a CardLayout will ignore both. In a BorderLayout, what is respected or ignored depends on the location - BorderLayout.NORTH & SOUTH respect the preferred height, but ignore the preferred width, BorderLayout.CENTER ignores both.

Knowing how a LayoutManager handles preferred size is not enough, however. You also need to know what the default preferred size of a particular component is, and what the LayoutManager will do when it ignores the preferred size. This is why your Canvas is giving you trouble.

A Canvas by default has a preferred width of 0 and a preferred height of 0. FlowLayout *respects* preferred width and height. Therefore, when the Canvas is added to the layout its size will be set by a FLowLayout to 0,0 - and will therefore not be visible. BorderLayout.CENTER ignores the preferred size completely, and the default behavior is to stretch the component in both dimensions to fill the remaining space in the Container. So if you have an empty Container with a BorderLayout manager, your Canvas will fill be sized to fill the container if you add it to the CENTER> Adding to NORTH or SOUTH respects the preffered height, but stretches the Component to fill the width of the Container, while adding to EAST or WEST repsects the preferred width, but stretches the Component to fill the height of the Container.

Obviously, GLCanvas did not override the Canvas getPreferredSize method. And IIRC GLCanvas is final, so you will need to know the properties of each layout manager in order to use it effectively.

Offline shaddam_IV

Junior Devvie




Java makes me happy the way C# doesn't!


« Reply #6 - Posted 2003-12-06 12:33:24 »

Thanks for the info.  I have been doing C++/OpenGL programming for a while, but am new to Java.  Please pardon my ignorance.

There are 10 kinds of people in the world.  Those that understand binary and those that don't.
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (105 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!