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?).
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
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
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
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.