Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > help on gridBagLayout

Reply
Thread Tools

help on gridBagLayout

 
 
Mr. X.
Guest
Posts: n/a
 
      05-14-2008
Helo,
I think that gridBagLayout is the most complicated of the standard layouts.

I try to understand the following (see my thoughts after the asterisks ...)
:

// (The code is a class that implements the JPanel)
protected void makebutton(String name,

GridBagLayout gridbag,

GridBagConstraints c) {

JButton button = new JButton(name);

gridbag.setConstraints(button, c);

add(button);

button.addActionListener(this);

}


public void initX() {

GridBagLayout gridbag = new GridBagLayout();

GridBagConstraints c = new GridBagConstraints();


setFont(new Font("SansSerif", Font.PLAIN, 14));

setLayout(gridbag);


setComponentOrientation(ComponentOrientation.RIGHT _TO_LEFT);

c.anchor = GridBagConstraints.LINE_END;

c.weightx = 1;

c.weighty = 1;

c.fill = GridBagConstraints.VERTICAL;

c.anchor = GridBagConstraints.EAST;

makebutton("ButtonX", gridbag, c);


c.weightx = 1;

c.weighty = 1;

c.gridwidth = GridBagConstraints.REMAINDER;

c.fill = GridBagConstraints.BOTH;

c.anchor = GridBagConstraints.EAST;

makebutton("ButtonY", gridbag, c);

// *********************************

// *********************************

// *********************************

// ...

All I want to do is that : ButtonX will be at the east side of the panel,
and ButtonY will be at the rest of the panel.



What I get is that buttonX is OK, but buttonY is from left to a place where
the button seems as a square (what ever I try to do ...)

Since I am new to gridbaglayout , I need help of the above code, please.

I would like a good tutorial (that explains with some examples, every method
& field of GridBagConstraint), please.

What's wrong with my code ?

Thanks


 
Reply With Quote
 
 
 
 
Mr. X.
Guest
Posts: n/a
 
      05-14-2008
....
I want that both buttonX and buttonY will fill the whole JPanel (the
container that they are on).

Thanks


 
Reply With Quote
 
 
 
 
Mr. X.
Guest
Posts: n/a
 
      05-14-2008
Thanks ...

This doesn't much help, since I have problem on the above code, because
ButtonY doesn't fill the rest of the area of it's container.

(If I am not wrong, HTML table has width = *, which does the task, which is
simplier).


 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      05-14-2008
Mr. X. wrote:
> Helo,
> I think that gridBagLayout is the most complicated of the standard layouts.


True. That's one reason why I prefer ....
- other Layout Managers where appropriate
- nested layouts
- MigLayout
I JGoodies FormLayout is also better in many respects

>
> [code snipped]
>
> All I want to do is that : ButtonX will be at the east side of the panel,
> and ButtonY will be at the rest of the panel.
>
>
>
> What I get is that buttonX is OK, but buttonY is from left to a place where
> the button seems as a square (what ever I try to do ...)
>
> Since I am new to gridbaglayout , I need help of the above code, please.
>


Try playing with Knute Johnson's teaching applet
http://rabbitbrush.frazmtn.com/gridbagtester.html


> I would like a good tutorial (that explains with some examples, every method
> & field of GridBagConstraint), please.


http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html





--
RGB
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-14-2008
On Wed, 14 May 2008 15:52:29 +0300, "Mr. X."
<no_spam_please@nospam_please.com> wrote, quoted or indirectly quoted
someone who said :

>I think that gridBagLayout is the most complicated of the standard layouts


see http://mindprod.com/jgloss/gridbaglayout.html

for some hints on how to make it jump through hoops.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-14-2008
On Wed, 14 May 2008 15:52:29 +0300, "Mr. X."
<no_spam_please@nospam_please.com> wrote, quoted or indirectly quoted
someone who said :

>
>All I want to do is that : ButtonX will be at the east side of the panel,
>and ButtonY will be at the rest of the panel.


GridBagConstraints.BOTH
weightx 100%
ipadx
are your tools to make a cell wider
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      05-14-2008
Great !
That's work.

A thing I don't understand is,
why when for both "ButtonX" and "ButtonY", when the weightx = 1,
then I have the problem I have described (the buttons don't both fill their
container),
and when ButtonX's weight=0, and ButtonY=1, everything works fine.

Thanks


 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      05-15-2008
Mr. X. wrote:
> Great !
> That's work.
>
> A thing I don't understand is,
> why when for both "ButtonX" and "ButtonY", when the weightx = 1,
> then I have the problem I have described (the buttons don't both fill their
> container),
> and when ButtonX's weight=0, and ButtonY=1, everything works fine.
>
> Thanks
>
>


Is the container bigger than the buttons? GBL will only take more space
if there is more space to take.

--

Knute Johnson
email s/nospam/linux/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple GridBagLayout Question AJ Java 6 06-14-2004 05:32 PM
Viewing GridBagLayout's Grid Lines? John Davison Java 6 12-10-2003 10:03 PM
GridBagLayout Example David McCallum Java 0 10-23-2003 04:12 PM
GridBagLayout and JTextField me Java 2 07-21-2003 02:59 PM
grid or gridbaglayout Passero Java 3 07-02-2003 09:21 PM



Advertisments