• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

same old gridbag

 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my preffered layout model
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see either of your pictures. What do want it to look like?
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your link goes to a yahoo error page for me.
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no solutions?. i's urgent for me
basha
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nate got the problom right.but i say GBL is not well documented.
basha
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic