• 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

Wonky Margins and Sizes

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
This is a continued post from earlier today as the situation as evolved.

I am trying to make a GUI in Java (code only) looking like this :

https://i.imgur.com/9fzkElQ.png


I've started by adding a MainPanel with a BorderLayout
and assigning a JList to the WEST. This seems to be working well.


Next added a Center Panel with 2 columns for mid section to the CENTER of the MainPanel.



Then I added the left panel to the centerPanel which will be my input area.

(one extra row because I might add stuff later, or try to find a way to add a gap spacer to keep it away from bottom of page)

Then I wrote methods to
add my various Panels to this centerPanel_Input.




However, when displayed, there are all sorts of questionable Gaps.
For instance, there's a GIANT gap between Jpanel top and Jpanel midList, but no gap at all between JPanel midList and JPanel bottom??


https://i.imgur.com/aY66mkv.png


Any idea why?


lastly,

I have two problems with SetUpManualArea

I can't control the size of the elements, so the JTextFields are blarringly gross sizes,
along with the button as well.
Tried set Min, Max and preferred size.

I also can't seem to control the order despite trying to add them to the right column/row.
For example, inLabelTop at (0,0) appears last like its at (0,2)


https://i.imgur.com/I84TjZ2.png



Your help is greatly appreciated in these trying times!



 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to pick one thing: a GridLayout makes all of its cells the same size. So your layout which uses a GridLayout with 1 row and 3 columns has three cells arranged vertically, all the same size. But that isn't how your target layout looks -- the top cell needs to be much smaller than the other two. You would probably find that a FlowLayout or a BoxLayout would work better there.

Looking through my code, I don't ever explicitly set the size of a JTextField, minimum, preferred, or otherwise. Swing will generally pick a good size for it. But in your case the GridLayout coerces the JTextField to fill the whole cell, which isn't what you want.

Edit: When you start out with this layout manager business, there's usually the temptation to control the size of components by setting their size. That bottom-up strategy can be made to work but it's brittle, in that resizing the window or running the code on a monitor with different resolution can break it. It's better to use the top-down strategy where the layout managers set the sizes based on how they fit together.
 
Steve Datz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks paul for your suggestion.

I've went with the BoxLayout because It seems flow layout is only horizontal?


This is the new result:


https://i.imgur.com/QczbouZ.png

Still have tons of extreme spacing issues and random sizes
 
Steve Datz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've added in some dummy spacing with :



looks  a bit better now, but something is still very off about the bottom GridLayout,
I will have to come up with another solution and split it into 2 Panels I think

https://imgur.com/Jk7IyJQ
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is your SSCCE?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Datz wrote:I will have to come up with another solution and split it into 2 Panels I think



Yes, splitting the display like that is often a good strategy which gives you more control.
 
Steve Datz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:Where is your SSCCE?



Rob, I apologize, I am not sure how'd id make an SSCCE without ripping apart all my code and logic.
If I were to paste parts in and make it solely in the browser I would probably miss some steps that would make it look bugged on its own.

I believe that breaking down my code into steps (and small ones!) would be enough to make it clear what my code is doing.

I am not expecting someone to debug the entire project, I hope you'll forgive me for this.


I am getting much closer!
https://i.imgur.com/DiRJ3ku.png
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to fit components into a panel perfectly and resize perfectly you use a jgridbaglayout.

If you know how an html table tag uses the cols= and rows= , it makes a grid over the (jpanel) rectangle like geographic map and you assign each component a square unit size X * y of the grid.

There is another answer in the other thread on swing components.
 
reply
    Bookmark Topic Watch Topic
  • New Topic