AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newbie: GridBagLayout adjustement to Conatiner size

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Sergio
Guest





PostPosted: Sat Sep 27, 2003 1:24 am    Post subject: newbie: GridBagLayout adjustement to Conatiner size Reply with quote



Hi all,
maybe it is a silly question, but I've been unable to find the answer.
I created a class that extends JInternalFrame that contains only three
components that I would like to lay out using a GridBagLayout.

Component 1 is a JTextField, component 2 is a JButton, and component 3
is JEditorPane.
After creating the components, and setting the size of the
JInternalFrame-derived object, I tried the following:

Container mainPane = getContentPane();

mainPane.setLayout(new GridBagLayout());

GridBagConstraints cons = new GridBagConstraints();

cons.fill=cons.BOTH;

cons.gridx=0;
cons.gridy=0;
cons.gridwidth=8;
cons.gridheight=1;

mainPane.add(theTextField,cons);

cons.gridx=8;
cons.gridwidth=2;

mainPane.add(theJButton,cons);

cons.gridx=0;
cons.gridy=1;
cons.gridwidth=10;
cons.gridheight=10;

mainPane.add(new JScrollPane(theEditorPane),cons);

I expected something like:

______________________________
Quote:
theJTextField |theJButton|
-------------------------------
|
|
theJEditorPane |
|
|
-------------------------------



Although the lay out of the components is Ok, I would like them to fit
the size of the JInternalFrame, in a similar way to what occurs when
using a GridLayout. However, I have been unable to find a simple way of
doing this and avoiding to change the minimumSize properties of every
individual component...

Suggestions are very welcome

Sergio


Back to top
Roedy Green
Guest





PostPosted: Sat Sep 27, 2003 1:54 am    Post subject: Re: newbie: GridBagLayout adjustement to Conatiner size Reply with quote



On Fri, 26 Sep 2003 18:24:38 -0700, Sergio <yokese (AT) yahoo (DOT) es> wrote or
quoted :

Quote:
Component 1 is a JTextField, component 2 is a JButton, and component 3
is JEditorPane.

you can simplify things by having only two rows and two columns. You
don't specify the relative sizes of things by adding extra dummy
columns. Use weightx and weighty instead. See
http://mindprod.com/jgloss/gridbaglayout.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Back to top
Sergio
Guest





PostPosted: Sat Sep 27, 2003 5:47 am    Post subject: Re: newbie: GridBagLayout adjustement to Conatiner size Reply with quote



Thanks a lot. That solved the thing, although I still don't understand
why the other (bad) method gave a so different result.... I guess I need
to read more about layout managers.
Sergio

Roedy Green wrote:
Quote:
On Fri, 26 Sep 2003 18:24:38 -0700, Sergio <yokese (AT) yahoo (DOT) es> wrote or
quoted :


Component 1 is a JTextField, component 2 is a JButton, and component 3
is JEditorPane.


you can simplify things by having only two rows and two columns. You
don't specify the relative sizes of things by adding extra dummy
columns. Use weightx and weighty instead. See
http://mindprod.com/jgloss/gridbaglayout.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.