• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Using GridBagLayout in GUI

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My GUI classes are very similar to Monkhouse , with an exception. I have used a combination of GridBagLayout and BorderLayout managers in my Main application class. Since this is the first time I am coding in Swing, I wasn't sure if I am making it too complicated using the above.
With a lot of trying, I got the GUI to look good, but the search and the book panels are not equally aligned to the smart eyes. I mean to say that it seems to be aligned, but if you take a printout and measure it, it is not so. Will that cost me points? This is the best I could do

Thanks!
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nina,

I also use combination of BorderLayout and GridBagLayout, and i didn't thin i have an overcomplicated implementation. Could you explain more why you think your implementetion is too complicated? when you says aling what result you want to obtain making this align?

Regards.
 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Gabriel for your response. I am glad that you are also using the GridBagLayout Manager. The reason for my concern was because of something I read on the internet about GridBagLayout being too intricate and I did not want to make my app too complicated. But, personally I was able to do it easier with GridBagLayout than any other Layouts.
I have two panels beneath the JTable. One is the search panel and the other is the book panel. The fields in the search panel by itself are aligned perfectly so as the fields in the book panel. But, the search panel and the book panel fields are not aligned. I did some tweaking with the "insets" and I got it pretty close , but not 100% perfect.
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nina,

The weigthx and weighty attributes of GridBagConstraints can helps you. These attributes distribute the extra space into the maximun values per column defined. To this extra space sum the size of each component and you have the size of the cell (also sum the insets), so if you want to align the components these must have the same configuration of weightx and/or weighty and have the same width and/or height if you are working with two GridBagLayout separatedly.

In my main window i put the search functionality above the table centered and the book funcionality bellow of this table to the right so i don't nedd to align these components (i left to make the test with a end user to improve my gui design).

I hope it helps you.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a thought, something I learned in school a few years back. I am using a null layout for my GUI. You have to lay everything out according to X and Y locations. A little tedious, but easier than GridBag. That is why the instructor suggested it. GridBag has a pretty steep learning curve and can be complex. I think you have total control over placement by setting layout to null.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anne,
Sounds like something I would like to try but I do have a question. By setting the layout to null, and having to give exact coordinates, how does resizing work? Would it resize automatically?
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I'm going to guess that resizing works. I'm at work right now and don't have access to my code! We had to recreate the Windows calculator in that class, and it did work really well as far as placing items. I'm pretty sure the size is relative to whatever environment you are running the app on. I did something else that involved resizing and different PC formats. Toolkit getDefaultToolkit() comes to mind...maybe Component setSize(), and Dimension class might be good places to look in API. Good luck with your project.
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anne,

No use of layout make you implement functionality provided for a layout (this wolud be a hard work, make test over most platforms). Also this could be again one of the "advices" in the assigment:


Use of functionality provided by the core Java classes will be preferred to your own implementation of that functionality, unless there is a specific advantage to providing your own implementation.



Also the GridBagLaout is a flexible layout where you can perform most configuration for a GUI.

I hope it helps you.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic