aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes same old gridbag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "same old gridbag" Watch "same old gridbag" New topic
Author

same old gridbag

basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
hi nate,
A little slow to reply on previous post.
i am sending my code here,
i need a UI like as my attchment picture shows(what about javaranch attachment?).

here 's my code..

then a custom panel.



lovingly
basha
basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
here is my preffered layout model
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
I can't see either of your pictures. What do want it to look like?
basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
click this link for my image.
desiredlayout
i have successfully made a model as shown in my pic.(just run my code).the problom is,
when i replaces an empty panel with a custom panel,Stretching becomes ubnormal..
plz try this by uncommenting this line from my first class
jPanel4 = new javax.swing.JPanel();
to
jPanel4=new ControlPanel();(now commented)
anybody plz
basha
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Your link goes to a yahoo error page for me.
basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
error?.
i m getting picture here.if u dont mind,plz care to compile and run my code.u'll get a small window.maximise it.that is the model i needed.
so what's my problom?
plz read comments in my first class which is coming in 'initComponents()' method.look the difference(Stretching).OK?.problm is easy.but answer..i donno
plz care to remove 'package testpackage;' from first line.
basha
basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
no solutions?. i's urgent for me
basha
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Try this change. Instead of creating a new GridBagConstaint. Use the existing one and set the fields.
I did run the code and do not see what you mean.
basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
Hi poul.
My problom is,
i need a JFrame with 5 panels.panels are in different size.so i've decided to use GridBagLayout in my JFrame.all of my panels are custom classes(eg:MyPanel extends JPanel) with some additional functionalities.
first i made a JFrame with 5 empty JPanels.then i arranged this panels according to my preference using GridBagConstraints.this class is my fist class(PlaneUI.java).if u compile and run PlaneUI.java,u can see five empty panels.i have achieved my preffered layout with empty panels.PlaneUI is my model.no problom with it.(plz run PlaneUI.javayou can see my preffered model by maximising it).
then i started replacing empty panels with custum panels.when doing so the arrangement changes abnormally.in PlaneUI class there is a method named 'initComponents().within initComponents method,look linenumber:8 , u can see a commented line which is creating a custom panel called ControlPanel(code shown below) as the reference of jPanel4.please uncomment this line and comment previous line.run it.maximise window.look the difference.stretching become strange.got my problom?.
appreciating ur attention towards this issue.
basha
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I think it's because when you are just using JPanels they are free to resize however they want because they don't have a minimum size. When you add the custom panel with the buttons it does have a minimum size because the buttons inside cannot be made smaller than a certain amount or buttons will disappear or text will be unreadable. Using GridLayout in the custom panel only accentuates the problem because then all buttons must be as large as the largest button.

I know that's not all of the problem because even with specifying vertical fill only, the buttons take up more width than they should... GridBagLayout is probably doing some internal calculations based on minimum, maximum, and preferred size to actually calculate how large the panels should be...

My suggestion would be to make the final panels and then add them to the main panel to see how they fit together... GridBagLayout does not absolutely constrain the child components...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
basha khan
Ranch Hand

Joined: Jan 26, 2002
Posts: 516
nate got the problom right.but i say GBL is not well documented.
basha
 
Don't get me started about those stupid light bulbs.
 
subject: same old gridbag